Skip to content

Commit

Permalink
Close #71 Polishes sewage data
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaMarkic committed Jan 23, 2021
1 parent 45f224a commit 7aa051f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
33 changes: 20 additions & 13 deletions sources/SloCovidServer/SloCovidServer/Mappers/SewageMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,35 @@ public ImmutableArray<SewageDay> GetFromRaw(string raw)
foreach (string line in IterateLines(lines))
{
var fields = ParseLine(line);
var cities = ImmutableDictionary<string, SewageCityDay>.Empty;
var plants = ImmutableDictionary<string, ImmutableDictionary<string, float?>>.Empty;
foreach (var pair in header)
{
string[] parts = pair.Key.Split('.');
if (parts.Length == 3)
{
string cityName = parts[1];
if (!cities.TryGetValue(cityName, out var city))
float? value = GetFloat(fields[pair.Value]);
string plantName = parts[1];
if (value.HasValue)
{
city = new SewageCityDay(ImmutableDictionary<string, float?>.Empty);
if (!plants.TryGetValue(plantName, out var plant))
{
plant = ImmutableDictionary<string, float?>.Empty;
}
plant = plant.Add(parts[2], value);
plants = plants.SetItem(plantName, plant);
}
city = city with { Measurements = city.Measurements.Add(parts[2], GetFloat(fields[pair.Value])) };
cities = cities.SetItem(cityName, city);
}
}
var date = GetDate(fields[dateIndex]);
result.Add(new SewageDay(
date.Year,
date.Month,
date.Day,
cities
));
if (plants.Count > 0)
{
var date = GetDate(fields[dateIndex]);
result.Add(new SewageDay(
date.Year,
date.Month,
date.Day,
plants
));
}
}
return result.ToImmutableArray();
}
Expand Down
3 changes: 1 addition & 2 deletions sources/SloCovidServer/SloCovidServer/Models/SewageDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

namespace SloCovidServer.Models
{
public record SewageDay(int Year, int Month, int Day, ImmutableDictionary<string, SewageCityDay> Cities) { }
public record SewageCityDay(ImmutableDictionary<string, float?> Measurements) { }
public record SewageDay(int Year, int Month, int Day, ImmutableDictionary<string, ImmutableDictionary<string, float?>> Plants) { }
}

0 comments on commit 7aa051f

Please sign in to comment.