Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
9254d554
Commit
9254d554
authored
Mar 12, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Data models changes
parent
035622d5
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
78 additions
and
19 deletions
+78
-19
1Weather/Network/Model/HelperObjects/WdtDailySummariesArray.swift
+21
-1
1Weather/Network/Model/HelperObjects/WdtHourlySummariesArray.swift
+25
-1
1Weather/Network/Model/WdtDailySummary.swift
+8
-3
1Weather/Network/Model/WdtHourlySummary.swift
+9
-4
1Weather/Network/Model/WdtLocation.swift
+7
-7
1Weather/Network/Model/WdtSurfaceObservation.swift
+8
-3
No files found.
1Weather/Network/Model/HelperObjects/WdtDailySummariesArray.swift
View file @
9254d554
...
...
@@ -11,6 +11,13 @@ import Foundation
/// Needed for XMLCoder to decode the array with the right key name
struct
WdtDailySummariesArray
:
Codable
{
private
static
let
dateFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
timeZone
=
TimeZone
(
abbreviation
:
"PST"
)
fmt
.
dateFormat
=
"MM/dd/YYYY"
return
fmt
}()
let
items
:
[
WdtDailySummary
]
private
enum
CodingKeys
:
String
,
CodingKey
{
...
...
@@ -18,10 +25,23 @@ struct WdtDailySummariesArray: Codable {
case
items
=
"daily_summary"
}
init
(
from
decoder
:
Decoder
)
throws
{
func
validate
(
dateString
:
String
)
->
Bool
{
return
WdtDailySummariesArray
.
dateFormatter
.
date
(
from
:
dateString
)
!=
nil
}
let
container
=
try
decoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
var
rawItems
=
try
container
.
decode
([
WdtDailySummary
]
.
self
,
forKey
:
.
items
)
rawItems
=
(
rawItems
.
filter
{
validate
(
dateString
:
$0
.
dateLocal
)
})
self
.
items
=
rawItems
}
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
throws
->
[
DailyWeather
]
{
var
result
=
[
DailyWeather
]()
for
item
in
items
{
result
.
append
(
try
item
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
))
if
let
appModel
=
item
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
{
result
.
append
(
appModel
)
}
}
return
result
}
...
...
1Weather/Network/Model/HelperObjects/WdtHourlySummariesArray.swift
View file @
9254d554
...
...
@@ -10,6 +10,13 @@ import Foundation
/// Needed for XMLCoder to decode the array with the right key name
struct
WdtHourlySummariesArray
:
Codable
{
private
static
let
dateFormatter
:
DateFormatter
=
{
let
fmt
=
DateFormatter
()
fmt
.
timeZone
=
TimeZone
(
abbreviation
:
"PST"
)
fmt
.
dateFormat
=
"YYYY-MM-dd HH:mm:ss"
return
fmt
}()
let
items
:
[
WdtHourlySummary
]
private
enum
CodingKeys
:
String
,
CodingKey
{
...
...
@@ -17,10 +24,27 @@ struct WdtHourlySummariesArray: Codable {
case
items
=
"hourly_summary"
}
init
(
from
decoder
:
Decoder
)
throws
{
func
validate
(
dateString
:
String
)
->
Bool
{
let
result
=
WdtHourlySummariesArray
.
dateFormatter
.
date
(
from
:
dateString
)
if
result
==
nil
{
print
(
"[WdtHourly] Could't validate date:
\(
dateString
)
"
)
}
return
result
!=
nil
}
let
container
=
try
decoder
.
container
(
keyedBy
:
CodingKeys
.
self
)
var
rawItems
=
try
container
.
decode
([
WdtHourlySummary
]
.
self
,
forKey
:
.
items
)
rawItems
=
(
rawItems
.
filter
{
validate
(
dateString
:
$0
.
dateTimeLocal
)
})
self
.
items
=
rawItems
}
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
throws
->
[
HourlyWeather
]
{
var
result
=
[
HourlyWeather
]()
for
item
in
items
{
result
.
append
(
try
item
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
))
if
let
appModel
=
item
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
{
result
.
append
(
appModel
)
}
}
return
result
}
...
...
1Weather/Network/Model/WdtDailySummary.swift
View file @
9254d554
...
...
@@ -41,12 +41,16 @@ struct WdtDailySummary: Codable {
case
moonsetUtc
=
"solunar_moonset_utc"
}
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
throws
->
DailyWeather
{
private
static
let
log
=
Logger
(
componentName
:
"WdtDailySummary"
)
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
DailyWeather
?
{
let
log
=
WdtDailySummary
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"MM/dd/YYYY"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
dateLocal
)
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"daily.date:
\(
dateLocal
)
"
)
log
.
error
(
"Failed to parse date from:
\(
dateLocal
)
"
)
return
nil
}
var
weekDay
=
WeekDay
(
rawValue
:
self
.
weekDay
)
...
...
@@ -56,7 +60,8 @@ struct WdtDailySummary: Codable {
weekDay
=
WeekDay
(
grigorianWeekDayNumber
:
calendar
.
component
(
.
weekday
,
from
:
date
))
}
guard
let
weekDayUnwrapped
=
weekDay
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"daily.weekday:
\(
self
.
weekDay
)
"
)
log
.
error
(
"Couldn't parse week day:
\(
self
.
weekDay
)
"
)
return
nil
}
var
result
=
DailyWeather
(
lastTimeUpdated
:
updatedAt
,
date
:
date
,
timeZone
:
timeZone
,
weekDay
:
weekDayUnwrapped
)
...
...
1Weather/Network/Model/WdtHourlySummary.swift
View file @
9254d554
...
...
@@ -34,13 +34,17 @@ struct WdtHourlySummary: Codable {
case
weatherCode
=
"wx_code"
}
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
throws
->
HourlyWeather
{
private
static
let
log
=
Logger
(
componentName
:
"WdtHourlySummary"
)
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
HourlyWeather
?
{
let
log
=
WdtHourlySummary
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"YYYY-MM-dd HH:mm:ss"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
self
.
dateTimeLocal
)
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"hourly.date:
\(
self
.
dateTimeLocal
)
"
)
guard
let
date
=
dateFormatter
.
date
(
from
:
dateTimeLocal
)
else
{
log
.
error
(
"Failed to parse date from:
\(
dateTimeLocal
)
"
)
return
nil
}
var
weekDay
=
WeekDay
(
rawValue
:
self
.
weekDay
)
...
...
@@ -50,7 +54,8 @@ struct WdtHourlySummary: Codable {
weekDay
=
WeekDay
(
grigorianWeekDayNumber
:
calendar
.
component
(
.
weekday
,
from
:
date
))
}
guard
let
weekDayUnwrapped
=
weekDay
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"hourly.weekday:
\(
self
.
weekDay
)
"
)
log
.
error
(
"Couldn't parse week day:
\(
self
.
weekDay
)
"
)
return
nil
}
let
isDay
=
dayNight
.
trimmingCharacters
(
in
:
.
whitespacesAndNewlines
)
.
lowercased
()
==
"day"
...
...
1Weather/Network/Model/WdtLocation.swift
View file @
9254d554
...
...
@@ -37,17 +37,17 @@ struct WdtLocation: Codable {
if
let
lat
=
CLLocationDegrees
(
lat
??
""
),
let
lon
=
CLLocationDegrees
(
lon
??
""
)
{
coordinates
=
CLLocationCoordinate2D
(
latitude
:
lat
,
longitude
:
lon
)
}
var
today
=
try
surfaceObservation
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
var
today
=
surfaceObservation
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
let
dailyWeather
=
try
dailySummaries
?
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
??
[
DailyWeather
]()
let
hourlyWeather
=
try
hourlySummaries
?
.
toAppModel
(
timeZone
:
timeZone
,
updatedAt
:
updatedAt
)
??
[
HourlyWeather
]()
if
let
firstDay
=
dailyWeather
.
first
{
today
.
minTemp
=
firstDay
.
minTemp
today
.
maxTemp
=
firstDay
.
maxTemp
today
.
precipitationProbability
=
firstDay
.
precipitationProbability
today
.
sunState
=
firstDay
.
sunState
today
.
moonState
=
firstDay
.
moonState
today
.
moonPhase
=
firstDay
.
moonPhase
today
?
.
minTemp
=
firstDay
.
minTemp
today
?
.
maxTemp
=
firstDay
.
maxTemp
today
?
.
precipitationProbability
=
firstDay
.
precipitationProbability
today
?
.
sunState
=
firstDay
.
sunState
today
?
.
moonState
=
firstDay
.
moonState
today
?
.
moonPhase
=
firstDay
.
moonPhase
}
return
Location
(
lastTimeUpdated
:
updatedAt
,
...
...
1Weather/Network/Model/WdtSurfaceObservation.swift
View file @
9254d554
...
...
@@ -40,13 +40,17 @@ struct WdtSurfaceObservation: Codable {
case
sunsetLocalTime
=
"sunset_local"
}
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
throws
->
CurrentWeather
{
private
static
let
log
=
Logger
(
componentName
:
"WdtSurfaceObservation"
)
public
func
toAppModel
(
timeZone
:
TimeZone
,
updatedAt
:
Date
)
->
CurrentWeather
?
{
let
log
=
WdtSurfaceObservation
.
log
let
dateFormatter
=
DateFormatter
()
dateFormatter
.
dateFormat
=
"YYYY-MM-dd HH:mm:ss"
dateFormatter
.
timeZone
=
timeZone
guard
let
date
=
dateFormatter
.
date
(
from
:
self
.
dateTimeLocal
)
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"today.date:
\(
dateTimeLocal
)
"
)
log
.
error
(
"failed to parse date from:
\(
self
.
dateTimeLocal
)
"
)
return
nil
}
var
weekDay
=
WeekDay
(
rawValue
:
self
.
weekDay
)
if
weekDay
==
nil
{
...
...
@@ -55,7 +59,8 @@ struct WdtSurfaceObservation: Codable {
weekDay
=
WeekDay
(
grigorianWeekDayNumber
:
calendar
.
component
(
.
weekday
,
from
:
date
))
}
guard
let
weekDayUnwrapped
=
weekDay
else
{
throw
WdtWeatherSourceError
.
dataMergeError
(
"today.weekday:
\(
self
.
weekDay
)
"
)
log
.
error
(
"Couldn't parse weekDay from:
\(
self
.
weekDay
)
"
)
return
nil
}
let
isDay
=
dayNight
.
trimmingCharacters
(
in
:
.
whitespacesAndNewlines
)
.
lowercased
()
==
"day"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment