WIP: process layers
This commit is contained in:
@@ -172,29 +172,119 @@ namespace WebAPI.Controllers
|
|||||||
return BadRequest(e.ToString());
|
return BadRequest(e.ToString());
|
||||||
}
|
}
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("autoImportMorska/{apiKey}")]
|
[Route("AutoProcess/{apiKey}")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public IActionResult autoImportMorska(string apiKey)
|
public IActionResult AutoProcess(string apiKey)
|
||||||
{
|
{
|
||||||
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
if (Request.Host.Value != configuration["apiLocalUrl"] || apiKey != configuration["apiKey"])
|
||||||
{
|
{
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
morskaK5Parser parser = new morskaK5Parser(googleSheetValues, db);
|
List<Layer> processWorkerLayers;
|
||||||
Layer layer = parser.parse();
|
List<Layer> layersToProcess;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
processWorkerLayers = db.Layers
|
||||||
|
.Include(x => x.Records)
|
||||||
|
.Where(x => x.Records!.Any(x => x.Code == "Type" && x.Desc1 == "ProcessWorker"))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
layersToProcess = new List<Layer>();
|
||||||
|
|
||||||
|
foreach (Layer layer in processWorkerLayers)
|
||||||
|
{
|
||||||
|
string? sourceName = layer?.Records?.Single(x => x.Code == "Source")?.Desc1;
|
||||||
|
if (sourceName == null)
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = "Process error",
|
||||||
|
Type = LogEntryType.error,
|
||||||
|
LogType = LogType.import,
|
||||||
|
Message = layer?.Name + " Source record not found",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
return BadRequest();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Layer sourceLayer = db.Layers.Single(x => x.Name == sourceName);
|
||||||
|
if (sourceLayer == null)
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = "Process error",
|
||||||
|
Type = LogEntryType.error,
|
||||||
|
LogType = LogType.import,
|
||||||
|
Message = layer?.Name + " Source layer not found " + sourceLayer,
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
return BadRequest();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string startDate = sourceLayer.Records!.Where(x => x.Code == "StartDate").First().Desc1!;
|
||||||
|
string endDate = sourceLayer.Records!.Where(x => x.Code == "EndDate").First().Desc1!;
|
||||||
|
var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
|
||||||
|
var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
|
||||||
|
if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date)
|
||||||
|
{
|
||||||
|
string? processType = layer?.Records?.Single(x => x.Code == "ProcessType")?.Desc1;
|
||||||
|
if (processType == null)
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = "Process error",
|
||||||
|
Type = LogEntryType.error,
|
||||||
|
LogType = LogType.import,
|
||||||
|
Message = layer?.Name + " ProcessType record not found",
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
return BadRequest();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
switch (processType)
|
||||||
|
{
|
||||||
|
case "Copy":
|
||||||
|
break;
|
||||||
|
case "Deaggregate":
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Layer sourceLayer = db.Layers.Single(x => x.Name == layer.Records.Single(y => y.Code == "Source").Desc1);
|
||||||
|
|
||||||
AddLayer(layer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
// string startDate = layer.Records!.Where(x => x.Code == "StartDate").First().Desc1!;
|
||||||
|
/// string endDate = layer.Records!.Where(x => x.Code == "EndDate").First().Desc1!;
|
||||||
return Ok("OK");
|
// var startDateParsed = DateTime.ParseExact(startDate, "yyyy.MM.dd", null);
|
||||||
}
|
// var endDateParsed = DateTime.ParseExact(endDate, "yyyy.MM.dd", null);
|
||||||
|
// if (startDateParsed.Date <= DateTime.UtcNow.Date && endDateParsed.Date >= DateTime.UtcNow.Date)
|
||||||
|
// {
|
||||||
|
// processImportWorker(layer);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
logsController.AddEntry(new LogEntry
|
||||||
|
{
|
||||||
|
Title = "Process error",
|
||||||
|
Type = LogEntryType.error,
|
||||||
|
LogType = LogType.import,
|
||||||
|
Message = e.ToString(),
|
||||||
|
CreatedAt = DateTime.UtcNow
|
||||||
|
});
|
||||||
|
return BadRequest(e.ToString());
|
||||||
|
}
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Route("checkDates")]
|
[Route("checkDates")]
|
||||||
public IActionResult checkDates()
|
public IActionResult checkDates()
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ namespace WebAPI.Controllers
|
|||||||
case LogType.backup:
|
case LogType.backup:
|
||||||
type = "Backup";
|
type = "Backup";
|
||||||
break;
|
break;
|
||||||
|
case LogType.process:
|
||||||
|
type = "Process";
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
type = "Other"; // should never happen
|
type = "Other"; // should never happen
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -31,4 +31,10 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="dataProcessors\" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="dataProcessors\" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ namespace WebAPI.Models
|
|||||||
[Required]
|
[Required]
|
||||||
public Guid ModifiedById { get; set; }
|
public Guid ModifiedById { get; set; }
|
||||||
public User? ModifiedBy { get; set; }
|
public User? ModifiedBy { get; set; }
|
||||||
|
public Guid? parentId { get; set; }
|
||||||
|
public Layer? parent { get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ namespace WebAPI.Models
|
|||||||
}
|
}
|
||||||
public enum LogType {
|
public enum LogType {
|
||||||
import,
|
import,
|
||||||
backup
|
backup,
|
||||||
|
process
|
||||||
}
|
}
|
||||||
public class LogEntry
|
public class LogEntry
|
||||||
{
|
{
|
||||||
|
|||||||
62
WebAPI/dataProcessors/copy.processor.cs
Normal file
62
WebAPI/dataProcessors/copy.processor.cs
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
using Google.Apis.Sheets.v4;
|
||||||
|
using System.Globalization;
|
||||||
|
using WebAPI.Models;
|
||||||
|
|
||||||
|
namespace WebAPI.dataParsers
|
||||||
|
{
|
||||||
|
public class morskaK5Parser
|
||||||
|
{
|
||||||
|
private SpreadsheetsResource.ValuesResource googleSheetValues;
|
||||||
|
private AppDbContext db;
|
||||||
|
|
||||||
|
public morskaK5Parser(
|
||||||
|
SpreadsheetsResource.ValuesResource _googleSheetValues,
|
||||||
|
AppDbContext _db)
|
||||||
|
{
|
||||||
|
googleSheetValues = _googleSheetValues;
|
||||||
|
db = _db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Layer parse()
|
||||||
|
{
|
||||||
|
Layer layer = new Layer();
|
||||||
|
layer.Source = "GoogleSheet";
|
||||||
|
|
||||||
|
string sheetId = "1ZzndU8HjYqz5VKCcrVHBOFW8fqpYfwquclznX9q39Yk";
|
||||||
|
|
||||||
|
var range = "Sierpien_2023!B3:AR5";
|
||||||
|
|
||||||
|
var request = googleSheetValues.Get(sheetId, range);
|
||||||
|
var response = request.Execute();
|
||||||
|
var data = response.Values;
|
||||||
|
|
||||||
|
layer.Source = "GoogleSheet";
|
||||||
|
layer.Number = db.Layers.Count() + 1;
|
||||||
|
layer.Name = $"L{layer.Number}-I-{data[0][1]}-{data[0][2]}/{data[0][3]}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
|
||||||
|
layer.Type = LayerType.import;
|
||||||
|
|
||||||
|
List<Record> records = new List<Record>();
|
||||||
|
|
||||||
|
for (int i = 1; i < data[1].Count; i++)
|
||||||
|
{
|
||||||
|
float value;
|
||||||
|
|
||||||
|
if (
|
||||||
|
data[1][i].ToString()?.Length > 0 &&
|
||||||
|
float.TryParse(data[2][i].ToString(), CultureInfo.GetCultureInfo("pl-PL"), out value))
|
||||||
|
{
|
||||||
|
Record record = new Record();
|
||||||
|
record.Id = Guid.NewGuid();
|
||||||
|
record.Code = data[1][i].ToString();
|
||||||
|
record.Value1 = value;
|
||||||
|
record.CreatedAt = DateTime.UtcNow;
|
||||||
|
record.ModifiedAt = DateTime.UtcNow;
|
||||||
|
records.Add(record);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
layer.Records = records;
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
WebAPI/dataProcessors/deaggregation.processor.cs
Normal file
22
WebAPI/dataProcessors/deaggregation.processor.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Google.Apis.Sheets.v4;
|
||||||
|
using System.Globalization;
|
||||||
|
using WebAPI.Models;
|
||||||
|
|
||||||
|
namespace WebAPI.dataProcessors
|
||||||
|
{
|
||||||
|
public class copyProcessor
|
||||||
|
{
|
||||||
|
private AppDbContext db;
|
||||||
|
|
||||||
|
public copyProcessor(
|
||||||
|
AppDbContext _db)
|
||||||
|
{
|
||||||
|
db = _db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Layer process()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user