-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataFlow.js
69 lines (62 loc) · 1.75 KB
/
DataFlow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* eslint-disable no-undef */
/* eslint-disable no-unused-vars */
function addToIndexedDB(selectedStation) {
console.log(selectedStation);
//concatenate allResultColumns and DBResultColumns together
let tableheaders = Object.assign({}, allResultColumns, DBResultColumns);
//get keys
let Keys = Object.keys(tableheaders);
console.log(Keys.toString());
// Parse selectedStation JSON object
// Create the database
var db = new Dexie(selectedStation[0].station_id);
db.version(1).stores({
'weatherdata': Keys.toString(),
'metadata': Object.keys(stationMetadata).toString()
});
// Put the metadata into it
db.metadata.put({
station_id: selectedStation[0].station_id,
name: selectedStation[0].name,
latitude: selectedStation[0].latitude,
longitude: selectedStation[0].longitude,
elevation: selectedStation[0].elevation
});
getWeather(selectedStation);
}
function findStation(stationId) {
console.log(stationId + "putInFindStation");
// query the database for the station id
let reply = $.ajax({
url: 'FindStation.php',
data: {
'station_id': stationId
},
type: 'POST'
});
// console.log(reply);
return reply;
}
function saveStation(reply, stationId, PeriodBegin) {
// if the station id is not found, add the station to the database
if (reply == 'false') {
console.log(stationId)
console.log(NAME)
console.log(ELEVATION)
console.log(PeriodBegin)
let year = PeriodBegin.split('-');
year = year[0];
$.ajax({
url: 'SaveStation.php',
data: {
"station_id": stationId,
"name": NAME,
"latitude": LATITUDE,
"longitude": LONGITUDE,
"elevation": ELEVATION,
"year": year
},
type: 'POST'
});
}
}