Morsksa K5 data parser
This commit is contained in:
@@ -4,26 +4,25 @@
|
||||
<mat-toolbar color="secondary">
|
||||
Layer details
|
||||
<span class="fill-to-right"></span>
|
||||
<button mat-button (click)="export()">Export to Google</button>
|
||||
</mat-toolbar>
|
||||
<mat-card-content>
|
||||
<mat-grid-list cols="2" rowHeight="90px">
|
||||
<mat-grid-tile>
|
||||
<mat-form-field class="detail-input">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput formControlName="name">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
|
||||
<mat-grid-tile>
|
||||
<mat-form-field class="detail-input">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Source</mat-label>
|
||||
<input matInput formControlName="source">
|
||||
</mat-form-field>
|
||||
</mat-grid-tile>
|
||||
|
||||
<mat-grid-tile *ngIf="document">
|
||||
<mat-form-field class="detail-input">
|
||||
<mat-form-field appearance="outline">
|
||||
<mat-label>Created</mat-label>
|
||||
<input matInput disabled [value]="document.created">
|
||||
</mat-form-field>
|
||||
@@ -50,6 +49,7 @@
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let item; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
Checksum: {{valueSum}}
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</form>
|
||||
|
||||
@@ -5,7 +5,6 @@ import { UntypedFormGroup, UntypedFormBuilder, FormsModule, ReactiveFormsModule
|
||||
import { MatSort, MatSortable, MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableDataSource, MatTableModule } from '@angular/material/table';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { AuthService } from 'src/app/auth/auth.service';
|
||||
import { Layer } from 'src/app/models/layer.model';
|
||||
import { Record } from 'src/app/models/record.model';
|
||||
import { NotificationsService } from 'src/app/services/notifications.service';
|
||||
@@ -32,6 +31,8 @@ export class LayerDetailComponent implements OnInit {
|
||||
public form!: UntypedFormGroup;
|
||||
public document!: Layer;
|
||||
|
||||
valueSum = 0;
|
||||
|
||||
displayedColumns = environment.views.layers.recordColumns.split("|");
|
||||
dataSource!: MatTableDataSource<Record>;
|
||||
|
||||
@@ -54,6 +55,7 @@ export class LayerDetailComponent implements OnInit {
|
||||
this.form.disable();
|
||||
this.document.created = `${this.datePipe.transform(this.document.createdAt?.toDate(), 'short')}, ${this.document.createdBy?.userName}`;
|
||||
this.dataSource.sort.sort({ id: 'code', start: 'desc' } as MatSortable);
|
||||
this.valueSum = this.document.records.map(t => t.value || 0).reduce((acc, value) => acc + value, 0);
|
||||
}
|
||||
private async load(): Promise<Layer> {
|
||||
return await Layer.getById(this.route$.snapshot.paramMap.get('id') || "", this.http$);
|
||||
|
||||
@@ -6,15 +6,15 @@ export const environment = {
|
||||
appEnvironment: "local",
|
||||
production: false,
|
||||
api: {
|
||||
//url: "http://localhost:5400/api"
|
||||
url: "https://diunabi-morska.bim-it.pl/api"
|
||||
url: "http://localhost:5400/api"
|
||||
//url: "https://diunabi-morska.bim-it.pl/api"
|
||||
},
|
||||
google: {
|
||||
clientId: "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com"
|
||||
},
|
||||
views: {
|
||||
layers: {
|
||||
recordColumns: "code|value|desc1"
|
||||
recordColumns: "code|value"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -141,6 +141,25 @@ namespace WebAPI.Controllers
|
||||
layer.Name = $"W{layer.Number}-I-{sheetName}-{parsedSheet.date}-{DateTime.Now.ToString("yyyyMMddHHmm")}";
|
||||
AddLayer(layer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
|
||||
return Ok("OK");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("autoImportMorska/{apiKey}")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult autoImportMorska(string apiKey)
|
||||
{
|
||||
if (Request.Host.Value != "localhost:5400" || apiKey != configuration["apiKey"])
|
||||
{
|
||||
return Unauthorized();
|
||||
}
|
||||
|
||||
morskaK5Parser parser = new morskaK5Parser(googleSheetValues, db);
|
||||
Layer layer = parser.parse();
|
||||
|
||||
|
||||
AddLayer(layer, Guid.Parse("F392209E-123E-4651-A5A4-0B1D6CF9FF9D"));
|
||||
|
||||
return Ok("OK");
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
},
|
||||
"GoogleClientId": "107631825312-bkfe438ehr9k9ecb2h76g802tj6advma.apps.googleusercontent.com",
|
||||
"Secret": "8393AF8EAEF8478CB738D44858690F9C7E2D19F65896DD9FBAA3EB2A6F493E80",
|
||||
"apiKey": "9ecb2h76g802tF65896DD9FBAA3EB2A6F493",
|
||||
"apiKey": "10763478CB738D4ecb2h76g803478CB738D4e",
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Http": {
|
||||
|
||||
61
WebAPI/dataParsers/morskaK5.parser.cs
Normal file
61
WebAPI/dataParsers/morskaK5.parser.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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")}";
|
||||
|
||||
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.Value = value;
|
||||
record.CreatedAt = DateTime.UtcNow;
|
||||
record.ModifiedAt = DateTime.UtcNow;
|
||||
records.Add(record);
|
||||
};
|
||||
|
||||
}
|
||||
layer.Records = records;
|
||||
return layer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user