Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating to get things building #6

Merged
merged 5 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"paket": {
"version": "6.0.0-rc002",
"version": "7.2.1",
"commands": [
"paket"
]
Expand Down
18 changes: 12 additions & 6 deletions .paket/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
This value should match the version in the props generated by paket
If they differ, this means we need to do a restore in order to ensure correct dependencies
-->
<PropertyGroup Condition="'$(PaketPropsVersion)' != '5.185.3' ">
<PropertyGroup Condition="'$(PaketPropsVersion)' != '6.0.0' ">
<PaketRestoreRequired>true</PaketRestoreRequired>
</PropertyGroup>

Expand Down Expand Up @@ -236,13 +236,16 @@
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
<AllPrivateAssets>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4])</AllPrivateAssets>
<CopyLocal Condition="'%(PaketReferencesFileLinesInfo.Splits)' == '6'">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5])</CopyLocal>
<CopyLocal Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 6">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5])</CopyLocal>
<OmitContent Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 7">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[6])</OmitContent>
<ImportTargets Condition="%(PaketReferencesFileLinesInfo.Splits) &gt;= 8">$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[7])</ImportTargets>
</PaketReferencesFileLinesInfo>
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
<PrivateAssets Condition=" ('%(PaketReferencesFileLinesInfo.AllPrivateAssets)' == 'true') Or ('$(PackAsTool)' == 'true') ">All</PrivateAssets>
<ExcludeAssets Condition=" '%(PaketReferencesFileLinesInfo.Splits)' == '6' And %(PaketReferencesFileLinesInfo.CopyLocal) == 'false'">runtime</ExcludeAssets>
<ExcludeAssets Condition=" '%(PaketReferencesFileLinesInfo.Splits)' != '6' And %(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.CopyLocal) == 'false' or %(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.OmitContent) == 'true'">$(ExcludeAssets);contentFiles</ExcludeAssets>
<ExcludeAssets Condition=" %(PaketReferencesFileLinesInfo.ImportTargets) == 'false'">$(ExcludeAssets);build;buildMultitargeting;buildTransitive</ExcludeAssets>
<Publish Condition=" '$(PackAsTool)' == 'true' ">true</Publish>
<AllowExplicitVersion>true</AllowExplicitVersion>
</PackageReference>
Expand Down Expand Up @@ -362,7 +365,9 @@
PackageLicenseFile="$(PackageLicenseFile)"
PackageLicenseExpression="$(PackageLicenseExpression)"
PackageLicenseExpressionVersion="$(PackageLicenseExpressionVersion)"
PackageReadmeFile="$(PackageReadmeFile)" />
Readme="$(PackageReadmeFile)"
NoDefaultExcludes="$(NoDefaultExcludes)"/>

<PackTask Condition="$(UseMSBuild16_0_Pack)"
PackItem="$(PackProjectInputFile)"
PackageFiles="@(_PackageFiles)"
Expand Down Expand Up @@ -410,7 +415,8 @@
NuspecProperties="$(NuspecProperties)"
PackageLicenseFile="$(PackageLicenseFile)"
PackageLicenseExpression="$(PackageLicenseExpression)"
PackageLicenseExpressionVersion="$(PackageLicenseExpressionVersion)" />
PackageLicenseExpressionVersion="$(PackageLicenseExpressionVersion)"
NoDefaultExcludes="$(NoDefaultExcludes)" />

<PackTask Condition="$(UseMSBuild15_9_Pack)"
PackItem="$(PackProjectInputFile)"
Expand Down
2 changes: 1 addition & 1 deletion Build.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Helpers.fs" />
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ In this exercise you'll learn some F# through modifying and extending a web app

You'll need to install the following pre-requisites in order to build SAFE applications

* [.NET Core SDK](https://www.microsoft.com/net/download) 5.0 or higher
* [.NET SDK](https://www.microsoft.com/net/download) check the version defined in [global.json]
* [Node LTS](https://nodejs.org/en/download/)

You can use any editor, for this exercise we recommend
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "5.0.100",
"version": "7.0.304",
"rollForward": "latestMinor"
}
}
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
source https://api.nuget.org/v3/index.json
framework: net5.0

storage: none

nuget Elmish.SweetAlert
Expand Down
1 change: 0 additions & 1 deletion paket.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
STORAGE: NONE
RESTRICTION: == net5.0
NUGET
remote: https://api.nuget.org/v3/index.json
Elmish.SweetAlert (3.4)
Expand Down
2 changes: 1 addition & 1 deletion src/Client/Client.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<DefineConstants>FABLE_COMPILER</DefineConstants>
</PropertyGroup>
<ItemGroup>
Expand Down
52 changes: 41 additions & 11 deletions src/Server/Api.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,47 @@ let getLocationResponse postcode = async {
return response
}

let private asWeatherResponse (weather: Weather.MetaWeatherLocation.Root) =
{ WeatherType =
weather.ConsolidatedWeather
|> Array.countBy(fun w -> w.WeatherStateName)
|> Array.maxBy snd
|> fst
|> WeatherType.Parse

AverageTemperature =
weather.ConsolidatedWeather
|> Array.sumBy (fun r -> float r.TheTemp) }
let private asWeatherResponse (weather: Weather.OpenMeteoSearch.Root) =
let averageTemp =
weather.Hourly.Temperature2m
|> Array.average
|> float

let (|LessOrEqual|_|) threshold v =
if v <= threshold then Some ()
else None

let weatherType =
// WMO Weather interpretation codes (WW)
// https://open-meteo.com/en/docs
(*
0 Clear sky
1, 2, 3 Mainly clear, partly cloudy, and overcast
45, 48 Fog and depositing rime fog
51, 53, 55 Drizzle: Light, moderate, and dense intensity
56, 57 Freezing Drizzle: Light and dense intensity
61, 63, 65 Rain: Slight, moderate and heavy intensity
66, 67 Freezing Rain: Light and heavy intensity
71, 73, 75 Snow fall: Slight, moderate, and heavy intensity
77 Snow grains
80, 81, 82 Rain showers: Slight, moderate, and violent
85, 86 Snow showers slight and heavy
95 * Thunderstorm: Slight or moderate
96, 99 * Thunderstorm with slight and heavy hail
*)
match weather.CurrentWeather.Weathercode with
| LessOrEqual 0 -> WeatherType.Clear
| LessOrEqual 3 -> WeatherType.Hail
// have fun filling the blanks if you know weather english lexical
// and above table makes sense
| LessOrEqual 48 -> WeatherType.Showers
| LessOrEqual 67 -> WeatherType.Sleet
| LessOrEqual 86 -> WeatherType.Snow
| LessOrEqual 95 -> WeatherType.Thunder
| _ -> WeatherType.Apocalyptic

{ WeatherType = weatherType
AverageTemperature = averageTemp }

let getWeather postcode = async {
let! loc = GeoLocation.getLocation postcode
Expand Down
19 changes: 17 additions & 2 deletions src/Server/DataAccess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module GeoLocation =
type PostcodesIO = JsonProvider<"http://api.geonames.org/postalCodeLookupJSON?postalcode=1011&country=NL&username=dsyme">

let getLocation postcode = async {
let! info =
let! info =
$"http://api.geonames.org/postalCodeLookupJSON?postalcode={postcode}&country=NL&username=dsyme"
|> PostcodesIO.AsyncLoad
if info.Postalcodes.Length > 0 then
Expand All @@ -34,6 +34,7 @@ module GeoLocation =
let a = sin (deltaPhi / 2.0) * sin (deltaPhi / 2.0) + cos phi1 * cos phi2 * sin (deltaLambda / 2.0) * sin (deltaLambda / 2.0)
let c = 2.0 * atan2 (sqrt a) (sqrt (1.0 - a))
r * c * 1.<meter>
#if METAWEATHER_ALIVE

[<AutoOpen>]
module Weather =
Expand All @@ -48,4 +49,18 @@ module Weather =
return!
bestLocationId
|> sprintf "https://www.metaweather.com/api/location/%d"
|> MetaWeatherLocation.AsyncLoad }
|> MetaWeatherLocation.AsyncLoad }

#else

module Weather =

type OpenMeteoSearch = JsonProvider<"https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&current_weather=true&hourly=temperature_2m,relativehumidity_2m,windspeed_10m">

let getWeatherForPosition location = async {
let uri = $"https://api.open-meteo.com/v1/forecast?latitude={location.Latitude}&longitude={location.Longitude}&current_weather=true&hourly=temperature_2m,relativehumidity_2m,windspeed_10m"
let! result = OpenMeteoSearch.AsyncLoad uri

return result
}
#endif
2 changes: 1 addition & 1 deletion src/Server/Server.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include="paket.references" />
Expand Down
3 changes: 2 additions & 1 deletion src/Shared/Shared.fs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type WeatherType =
| HeavyCloud
| LightCloud
| Clear
| Apocalyptic

static member Parse =
let weatherTypes = FSharp.Reflection.FSharpType.GetUnionCases typeof<WeatherType>
Expand Down Expand Up @@ -56,7 +57,7 @@ type IDojoApi =
module Validation =
open System.Text.RegularExpressions

let isValidPostcode country postcode =
let isValidPostcode country (postcode: string) =
match country with
| "NL" -> Regex.IsMatch(postcode, @"^[1-9][0-9]{3}\s*(?:[a-zA-Z]{2})?$")
| "GB" -> Regex.IsMatch(postcode, @"([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\s?[0-9][A-Za-z]{2})")
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/Shared.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions.fs" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Client/Client.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Client.Tests.fs" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Server/Server.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Server.Tests.fs" />
Expand Down
2 changes: 1 addition & 1 deletion tests/Shared/Shared.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Shared.Tests.fs" />
Expand Down