Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added tide data, resolved issued #1

  • Loading branch information...
commit 3403ff5088ddc1b6fab7d3f97b8efdab5203b8c9 1 parent f826917
@jon-eckstein authored
View
BIN  ShouldITakeMyDogToFortFunstonNow.suo
Binary file not shown
View
56 src/Site/Controllers/HomeModule.cs
@@ -23,10 +23,14 @@ public HomeModule(IDecisionService ds)
{
var currentObservation = new CurrentObservation();
- var obs = GetWeatherObservation();
- if (obs == null)
+ var raw = GetRawWeatherData();
+ if (raw == null)
return Response.AsError(Nancy.HttpStatusCode.ServiceUnavailable, "Unable to get weather data.");
+ var obs = GetWeatherObservation(raw);
+ if (obs == null)
+ return Response.AsError(Nancy.HttpStatusCode.ServiceUnavailable, "Unable to get observation data.");
+
currentObservation.ObsDateDescription = obs.observation_time.Value;
currentObservation.Condition = obs.weather.Value;
currentObservation.WindMph = obs.wind_mph.Value;
@@ -40,6 +44,18 @@ public HomeModule(IDecisionService ds)
currentObservation.WindChill = windchill;
else currentObservation.WindChill = 0;
+ var tides = GetTideSet(raw);
+ if (tides != null)
+ {
+ var nextLowTide = (DateTime?)GetNextLowTide(tides.tideSummary);
+ if (nextLowTide.HasValue)
+ {
+ currentObservation.NextLowTide = nextLowTide.Value;
+ currentObservation.HoursUntilNextLowTide = (currentObservation.NextLowTide - DateTime.UtcNow).TotalHours;
+ }
+ }
+
+
currentObservation.GoFunston = (int)ds.GetDecision(currentObservation);
return Response.AsJson(currentObservation);
};
@@ -51,7 +67,7 @@ public HomeModule(IDecisionService ds)
}
- private dynamic GetWeatherObservation()
+ private dynamic GetRawWeatherData()
{
try
{
@@ -64,7 +80,7 @@ private dynamic GetWeatherObservation()
return null;
dynamic json = JObject.Parse(txtResponse);
- return (dynamic)json.current_observation;
+ return (dynamic)json;
}
catch
{
@@ -72,5 +88,37 @@ private dynamic GetWeatherObservation()
}
}
+ private dynamic GetWeatherObservation(dynamic rawWeather)
+ {
+ return (dynamic)rawWeather.current_observation;
+ }
+
+ private dynamic GetTideSet(dynamic rawWeather)
+ {
+ if (rawWeather.tide.tideSummary.Count > 0)
+ return (dynamic)rawWeather.tide;
+ else
+ return null;
+ }
+
+ private DateTime? GetNextLowTide(dynamic tideSummary)
+ {
+ foreach (var tide in tideSummary)
+ {
+ if (tide.data.type.Value == "Max Ebb")
+ {
+ var date = new DateTime(Convert.ToInt32(tide.utcdate.year.Value),
+ Convert.ToInt32(tide.utcdate.mon.Value),
+ Convert.ToInt32(tide.utcdate.mday.Value),
+ Convert.ToInt32(tide.utcdate.hour.Value),
+ Convert.ToInt32(tide.utcdate.min.Value),
+ 0,DateTimeKind.Utc);
+ return date;
+ }
+ }
+
+ return null;
+ }
+
}
}
View
37 src/Site/Models/CurrentObservation.cs
@@ -11,13 +11,12 @@ namespace ShouldITakeMyDogToFortFunstonNow.Models
[Serializable]
public class CurrentObservation
{
- //[Column(IsPrimaryKey = true, IsDbGenerated = true)]
- [Key]
- public object Id { get; set; }
- //[Column(CanBeNull=true)]
- public string ObsDateDescription { get; set; }
- //[Column(CanBeNull=true)]
private string condition;
+ private double hoursUntilNextLowTide = -1;
+
+ [Key]
+ public object Id { get; set; }
+ public string ObsDateDescription { get; set; }
public string Condition
{
get { return condition; }
@@ -28,21 +27,21 @@ public string Condition
ConditionCode = GetConditionCode(condition);
}
}
- //[Column(CanBeNull = false)]
- public int ConditionCode { get; set; }
- //[Column(CanBeNull = false)]
- public double WindMph { get; set; }
- //[Column]
- public double WindGustMph { get; set; }
- //[Column(CanBeNull = false)]
- public double Temp {get;set;}
- //[Column]
- public double WindChill { get; set; }
- //[Column(CanBeNull=true)]
+
+ public double HoursUntilNextLowTide
+ {
+ get { return hoursUntilNextLowTide; }
+ set { hoursUntilNextLowTide = value; }
+ }
+
+ public int ConditionCode { get; set; }
+ public double WindMph { get; set; }
+ public double WindGustMph { get; set; }
+ public double Temp {get;set;}
+ public double WindChill { get; set; }
public DateTime NextLowTide { get; set; }
public int WeatherScore { get; set; }
- public int TideScore { get; set; }
- //[Column(CanBeNull = false)]
+ public int TideScore { get; set; }
public int GoFunston { get; set; }
public CurrentObservation() { }
View
19 src/Site/Views/Home.html
@@ -79,10 +79,9 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
<dt>Wind</dt>
<dd data-bind="text: windText(), css: { maybe : windMph() < 25 && windMph() > 15 , no : windMph() > 25 }" /></dd>
<dt>Temp</dt>
- <dd data-bind="text: tempText(), css: { maybe : temp() > 45 && temp() < 60, no : temp() < 45 }" /></dd>
- <!--
+ <dd data-bind="text: tempText(), css: { maybe : temp() > 45 && temp() < 60, no : temp() < 45 }" /></dd>
<dt>Tide</dt>
- <dd data-bind="text: app.tideText(), css: { maybe : tideEvaler.totalScore() < 0, no : tideEvaler.totalScore() < -1 }" /></dd>-->
+ <dd data-bind="text: tideText(), css: { maybe : tideHours() > 10, no : tideHours() > 18 }" /></dd>
</dl>
<div data-bind="text: obsTime()" style="font-size:small"></div>
</div>
@@ -116,7 +115,10 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
windGustMph: ko.observable(0),
goFunston: ko.observable(5),
windText: ko.observable(''),
- tempText: ko.observable('')
+ tempText: ko.observable(''),
+ tideHours: ko.observable(0),
+ tideText: ko.observable(''),
+
};
console.log(viewModel);
@@ -148,6 +150,15 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
viewModel.tempText(result.Temp + 'F');
}
+ if(result.HoursUntilNextLowTide > -1)
+ {
+ viewModel.tideHours(result.HoursUntilNextLowTide);
+ viewModel.tideText('Next low tide in ' + result.HoursUntilNextLowTide.toFixed(2) + ' hours');
+ }else{
+ viewModel.tideHours(0);
+ viewModel.tideText('No tide data available.');
+ }
+
},
error: function (result) {
View
2  src/Site/Web.config
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
- <add key="dbPath" value="" />
+ <add key="dbPath" value="mongodb://localhost:27017/fortfunstonweather" />
<!--
<add key="MONGOLAB_URI" value="" />-->
</appSettings>
View
BIN  src/Site/bin/ShouldITakeMyDogToFortFunstonNow.dll
Binary file not shown
View
BIN  src/Site/bin/ShouldITakeMyDogToFortFunstonNow.pdb
Binary file not shown
View
18 src/Site/bin/Views/Home.html
@@ -79,10 +79,9 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
<dt>Wind</dt>
<dd data-bind="text: windText(), css: { maybe : windMph() < 25 && windMph() > 15 , no : windMph() > 25 }" /></dd>
<dt>Temp</dt>
- <dd data-bind="text: tempText(), css: { maybe : temp() > 45 && temp() < 60, no : temp() < 45 }" /></dd>
- <!--
+ <dd data-bind="text: tempText(), css: { maybe : temp() > 45 && temp() < 60, no : temp() < 45 }" /></dd>
<dt>Tide</dt>
- <dd data-bind="text: app.tideText(), css: { maybe : tideEvaler.totalScore() < 0, no : tideEvaler.totalScore() < -1 }" /></dd>-->
+ <dd data-bind="text: tideText(), css: { maybe : tideHours() > 10, no : tideHours() > 18 }" /></dd>
</dl>
<div data-bind="text: obsTime()" style="font-size:small"></div>
</div>
@@ -116,7 +115,9 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
windGustMph: ko.observable(0),
goFunston: ko.observable(5),
windText: ko.observable(''),
- tempText: ko.observable('')
+ tempText: ko.observable(''),
+ tideHours: ko.observable(0),
+
};
console.log(viewModel);
@@ -148,6 +149,15 @@ <h1 class="no">Error occured getting weather data. Try again or go to Fort Funst
viewModel.tempText(result.Temp + 'F');
}
+ if(result.HoursUntilNextLowTide > -1)
+ {
+ viewModel.tideHours(result.HoursUntilNextLowTide);
+ viewModel.tideText('Next low tide in ' + result.HoursUntilNextLowTide.toFixed(2) + ' hours');
+ }else{
+ viewModel.tideHours(0);
+ viewModel.tideText('No tide data available.');
+ }
+
},
error: function (result) {
View
BIN  src/Site/obj/Debug/DesignTimeResolveAssemblyReferences.cache
Binary file not shown
View
BIN  src/Site/obj/Debug/ShouldITakeMyDogToFortFunstonNow.dll
Binary file not shown
View
BIN  src/Site/obj/Debug/ShouldITakeMyDogToFortFunstonNow.pdb
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.