Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
samvdb committed Jun 21, 2023
1 parent 6aecdc9 commit 55f812d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
58 changes: 28 additions & 30 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,34 @@ type Tomorrow_Report struct {
}

type Tomorrow_Values struct {
CloudBase float64 `json:"cloudBase"`
CloudCeiling interface{} `json:"cloudCeiling"`
CloudCover int `json:"cloudCover"`
DewPoint float64 `json:"dewPoint"`
Evapotranspiration float64 `json:"evapotranspiration"`
FreezingRainIntensity int `json:"freezingRainIntensity"`
Humidity int `json:"humidity"`
IceAccumulation int `json:"iceAccumulation"`
IceAccumulationLwe int `json:"iceAccumulationLwe"`
PrecipitationProbability int `json:"precipitationProbability"`
PressureSurfaceLevel float64 `json:"pressureSurfaceLevel"`
RainAccumulation int `json:"rainAccumulation"`
RainAccumulationLwe int `json:"rainAccumulationLwe"`
RainIntensity int `json:"rainIntensity"`
SleetAccumulation int `json:"sleetAccumulation"`
SleetAccumulationLwe int `json:"sleetAccumulationLwe"`
SleetIntensity int `json:"sleetIntensity"`
SnowAccumulation int `json:"snowAccumulation"`
SnowAccumulationLwe int `json:"snowAccumulationLwe"`
SnowDepth int `json:"snowDepth"`
SnowIntensity int `json:"snowIntensity"`
Temperature float64 `json:"temperature"`
TemperatureApparent float64 `json:"temperatureApparent"`
UvHealthConcern int `json:"uvHealthConcern"`
UvIndex int `json:"uvIndex"`
Visibility int `json:"visibility"`
WeatherCode int `json:"weatherCode"`
WindDirection float64 `json:"windDirection"`
WindGust float64 `json:"windGust"`
WindSpeed float64 `json:"windSpeed"`
CloudBase float64 `json:"cloudBase"`
CloudCeiling float64 `json:"cloudCeiling"`
CloudCover float64 `json:"cloudCover"`
DewPoint float64 `json:"dewPoint"`
FreezingRainIntensity int `json:"freezingRainIntensity"`
Humidity float64 `json:"humidity"`
IceAccumulation int `json:"iceAccumulation"`
IceAccumulationLwe int `json:"iceAccumulationLwe"`
PrecipitationProbability int `json:"precipitationProbability"`
PressureSurfaceLevel float64 `json:"pressureSurfaceLevel"`
RainAccumulation int `json:"rainAccumulation"`
RainAccumulationLwe int `json:"rainAccumulationLwe"`
RainIntensity float64 `json:"rainIntensity"`
SleetAccumulation int `json:"sleetAccumulation"`
SleetAccumulationLwe int `json:"sleetAccumulationLwe"`
SleetIntensity int `json:"sleetIntensity"`
SnowAccumulation int `json:"snowAccumulation"`
SnowAccumulationLwe int `json:"snowAccumulationLwe"`
SnowIntensity int `json:"snowIntensity"`
Temperature float64 `json:"temperature"`
TemperatureApparent float64 `json:"temperatureApparent"`
UVHealthConcern int `json:"uvHealthConcern"`
UVIndex float64 `json:"uvIndex"`
Visibility int `json:"visibility"`
WeatherCode int `json:"weatherCode"`
WindDirection float64 `json:"windDirection"`
WindGust float64 `json:"windGust"`
WindSpeed float64 `json:"windSpeed"`
}

type DarkSky_Forecast struct {
Expand Down
15 changes: 7 additions & 8 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/rs/zerolog/log"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
"os"
"strconv"
Expand Down Expand Up @@ -89,9 +88,9 @@ func (s *Service) downloadReport(longitude, latitude float64) (*Tomorrow_Forecas
if err != nil {
return nil, err
}
dump, _ := httputil.DumpResponse(resp, true)
log.Debug().Msg("api response received")
fmt.Printf("%s", dump)
//dump, _ := httputil.DumpResponse(resp, true)
//log.Debug().Msg("api response received")
//fmt.Printf("%s", dump)
if resp.StatusCode != 200 {
return nil, fmt.Errorf("invalid response with code %d, error: %s", resp.StatusCode, resp.Status)
}
Expand Down Expand Up @@ -145,17 +144,17 @@ func (s *Service) WriteXML(w http.ResponseWriter, result interface{}) {
windBearing += 360
}
xml += fmt.Sprintf("<DD>%.0f</DD>", windBearing)
xml += fmt.Sprintf("<RR1H>%5.1f</RR1H>", hourly.Values.RainIntensity)
xml += fmt.Sprintf("<RR1H>%0.1f</RR1H>", hourly.Values.RainIntensity)
xml += fmt.Sprintf("<PP0>%.0f</PP0>", hourly.Values.PressureSurfaceLevel)
xml += fmt.Sprintf("<RH>%.0f</RH>", hourly.Values.Humidity*100)
xml += fmt.Sprintf("<HI>%.1f</HI>", hourly.Values.TemperatureApparent)
xml += fmt.Sprintf("<RAD>%4.0f</RAD>", hourly.Values.UvIndex*100)
xml += fmt.Sprintf("<RAD>%4.0f</RAD>", hourly.Values.UVIndex*100)
xml += fmt.Sprintf("<WW>%d</WW>", s.fixIcon(hourly))
xml += fmt.Sprintf("<FFX>%.1f</FFX>", hourly.Values.WindGust*100/3600)
xml += "<LC>0</LC>"
xml += fmt.Sprintf("<MC>%.0f</MC>", hourly.Values.CloudCover*100)
xml += "<HC>0</HC>"
xml += fmt.Sprintf("<RAD4C>%.0f</RAD4C>", hourly.Values.UvIndex)
xml += fmt.Sprintf("<RAD4C>%.0f</RAD4C>", hourly.Values.UVIndex)
xml += "</metdata>"
}
xml += "</metdata_feature_collection>\n"
Expand All @@ -168,5 +167,5 @@ func (s *Service) WriteXML(w http.ResponseWriter, result interface{}) {

func (s *Service) fixIcon(report Tomorrow_Report) int {
//return fixDarkSky2(report)
return fixTomorrow(report)
return getWeatherCondition(report.Values.WeatherCode)
}

0 comments on commit 55f812d

Please sign in to comment.