-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
223 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export const example = { | ||
"coord": { | ||
"lon": 18.24, | ||
"lat": 49.89 | ||
}, | ||
"weather": [ | ||
{ | ||
"id": 800, | ||
"main": "Clear", | ||
"description": "clear sky", | ||
"icon": "01n" | ||
} | ||
], | ||
"base": "stations", | ||
"main": { | ||
"temp": 279.15, | ||
"pressure": 1015, | ||
"humidity": 48, | ||
"temp_min": 279.15, | ||
"temp_max": 279.15 | ||
}, | ||
"visibility": 10000, | ||
"wind": { | ||
"speed": 7.7, | ||
"deg": 210 | ||
}, | ||
"clouds": { | ||
"all": 0 | ||
}, | ||
"dt": 1488132000, | ||
"sys": { | ||
"type": 1, | ||
"id": 5894, | ||
"message": 0.0039, | ||
"country": "CZ", | ||
"sunrise": 1488087277, | ||
"sunset": 1488126343 | ||
}, | ||
"id": 3071429, | ||
"name": "Ludgerovice", | ||
"cod": 200 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
/** | ||
* Created by Farmas on 23.02.2017. | ||
*/ | ||
import { Weather } from "./models/models"; | ||
import { IHour, Hour } from "./models/Hour/model"; | ||
import { Hour, IHour } from "./models/Hour/model"; | ||
|
||
export const fillDB = () => Weather.create({ | ||
temperature: 55, | ||
date: 'what a nice date' | ||
}); | ||
|
||
export const creteHour = (hour: IHour) => Hour.create(hour); | ||
export const persistHour = (hour: IHour) => | ||
Hour.findOneAndUpdate({hour: hour.hour}, { | ||
$set: { | ||
currentWeather: hour.currentWeather, | ||
predictedWeather: hour.predictedWeather, | ||
predictedValues: hour.predictedValues, | ||
} | ||
}, {upsert: true, new: true}) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Hour, HourC } from "../repository/models/Hour/model"; | ||
import { WeatherC, Weather } from "../repository/models/Weather/model"; | ||
import { persistHour } from "../repository/index"; | ||
/** | ||
* Created by Farmas on 26.02.2017. | ||
*/ | ||
export const insertHour = async(weather) => { | ||
let insertedHour = null; | ||
try { | ||
const detailedWeather = []; | ||
weather.weather.forEach(a => detailedWeather.push({ | ||
id: a.id, | ||
main: a.main, | ||
description: a.description | ||
})); | ||
const currentWeather = new Weather( | ||
new WeatherC( | ||
detailedWeather, | ||
weather.main.temp, | ||
weather.main.pressure, | ||
weather.main.humidity, | ||
weather.main.temp_min, | ||
weather.main.temp_max, | ||
weather.wind.speed, | ||
weather.wind.deg, | ||
)); | ||
const today = new Date(); | ||
const hour = new Hour(new HourC( | ||
today.getHours(), | ||
currentWeather, | ||
new Weather(new WeatherC()), | ||
"hello from parse5456" | ||
)); | ||
insertedHour = await persistHour(hour) | ||
} catch (e) { | ||
console.log("Ops"); | ||
console.log(e); | ||
throw new Error("Error creating hour " + e) | ||
} | ||
return insertedHour; | ||
}; |