Skip to content

Commit 8922b04

Browse files
Improve OCPI import, fix country code mapping
1 parent 416074a commit 8922b04

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

API/OCM.Net/OCM.API.Model/OCPI/OCPIDataAdapter.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,20 @@ private string GetCountryCodeFromISO3(string srcISO)
6060
foreach (var i in source)
6161
{
6262

63-
var iso2Code = i.Country_code;
63+
// Country_Code is the CPO owner country code, not the location country code
64+
// Country is the specified country code for the location but we fall back to the CPO owner country code if not specified
6465

65-
if (string.IsNullOrEmpty(iso2Code) && i.Country != null)
66+
var iso2Code = GetCountryCodeFromISO3(i.Country);
67+
68+
if (string.IsNullOrEmpty(iso2Code) && i.Country_code != null)
6669
{
67-
if (i.Country.Length == 2)
70+
if (i.Country_code.Length == 2)
6871
{
69-
iso2Code = i.Country.ToUpper();
72+
iso2Code = i.Country_code.ToUpper();
7073
}
7174
else
7275
{
73-
iso2Code = GetCountryCodeFromISO3(i.Country);
76+
iso2Code = GetCountryCodeFromISO3(i.Country_code);
7477
}
7578
}
7679

Import/OCM.Import.Common/ImportManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public async Task<List<ChargePoint>> DeDuplicateList(List<ChargePoint> cpList, b
287287
var allPOIs = new List<ChargePoint>();
288288
int? greaterThanId = null;
289289
bool moreData = true;
290-
const int pageSize = 1000; // adjust as needed for API limits
290+
const int pageSize = 10000; // adjust as needed for API limits
291291

292292
do
293293
{

Import/OCM.Import.Worker/Worker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private async void PerformTasks(object? state)
4646
_logger.LogInformation("Checking import status..");
4747

4848
var tempPath = Path.GetTempPath();
49-
49+
5050
try
5151
{
5252
var status = new ImportStatus { DateLastImport = DateTime.UtcNow, LastImportedProvider = "", LastImportStatus = "Started" };
@@ -89,7 +89,7 @@ private async void PerformTasks(object? state)
8989

9090
var apiKeys = _config.AsEnumerable().Where(k => k.Key.StartsWith("OCPI-") || k.Key.StartsWith("IMPORT-")).ToDictionary(k => k.Key, v => v.Value);
9191

92-
92+
9393
var importManager = new ImportManager(_settings, apiKeys["IMPORT-ocm-system"], _logger);
9494

9595
var importedOK = await importManager.PerformImportProcessing(

Tests/OCM.API.Tests/ImportTests/TestOCPIConversions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ async Task CanConvertFromOCPI_MobiePt()
258258
// ensure power KW does not exceed a reasonable value
259259
Assert.Empty(poiResults.Where(p => p.Connections.Any(c => c.PowerKW > 2000)));
260260

261-
var output = JsonConvert.SerializeObject(poiResults, Formatting.Indented, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
262-
263-
System.IO.File.WriteAllText("C:\\temp\\ocm\\ocpi.json", output);
264261
}
265262

266263
[Fact]
@@ -379,6 +376,13 @@ async Task CanConvertFromOCPI_PowerGO()
379376

380377
Assert.Equal(489, poiResults.Count());
381378

379+
380+
// check that we have POIs in both Norway and Netherlands
381+
var countries = poiResults.Select(p => p.AddressInfo.CountryID).Distinct().ToList();
382+
383+
Assert.Contains(159, countries); // Netherlands
384+
Assert.Contains(168, countries); // Norway
385+
382386
var unmappedOperators = adapter.GetPostProcessingUnmappedOperators();
383387

384388
foreach (var o in unmappedOperators.OrderByDescending(i => i.Value))
@@ -407,7 +411,7 @@ async Task CanConvertFromOCPI_PUnkt()
407411

408412
var poiResults = adapter.Process(coreRefData).ToList();
409413

410-
Assert.Equal(100, poiResults.Count());
414+
Assert.Equal(489, poiResults.Count());
411415

412416
var unmappedOperators = adapter.GetPostProcessingUnmappedOperators();
413417

0 commit comments

Comments
 (0)