Added function to Upload sql insert scripts to show a Graph of that

This commit is contained in:
Zam
2022-03-18 08:54:50 +01:00
parent d948cb7188
commit 387bc05345
3 changed files with 65 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ using System.Diagnostics;
using System.Net;
using System.Text;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Mvc;
using DataGeneratorMVC.Models;
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
@@ -31,7 +32,7 @@ public class HomeController : Controller
}
[HttpPost]
public IActionResult Index(GeneratorDataViewModel model, string cmd)
public IActionResult Index(GeneratorDataViewModel model, string cmd, IFormFile? file)
{
if (ModelState.IsValid)
{
@@ -44,16 +45,45 @@ public class HomeController : Controller
break;
case "save":
return File(Encoding.UTF8.GetBytes(model.Sql), "text/plain", "sql_insert.sql");
case "upload":
Upload(model, file);
break;
}
}
}
return View(model);
}
private void GenerateNew(GeneratorDataViewModel model)
private void Upload(GeneratorDataViewModel model, IFormFile up)
{
var tmp = DataGenerator.Generate(model.Settings);
var rgx = new Regex(@"(?<=\()(.*)(?=\))"); // Match only values of SQL Statement
var dict = new Dictionary<DateTime, double>();
using (var reader = new StreamReader(up.OpenReadStream()))
{
while (reader.Peek() >= 0)
{
string line = reader.ReadLine();
line = rgx.Match(line).Value;
string[] inputs = line.Split(",");
dict.Add(DateTime.Parse(inputs[1].Replace("\'", "")), Double.Parse(inputs[2]));
}
}
//var model = new GeneratorDataViewModel();
GenerateNew(model, dict);
}
private void GenerateNew(GeneratorDataViewModel model, Dictionary<DateTime, double>? input = null)
{
Dictionary<DateTime, double> tmp;
if (input != null)
tmp = input;
else
tmp = DataGenerator.Generate(model.Settings);
var labels = new List<double>();

View File

@@ -12,7 +12,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7040;http://localhost:5143",
"applicationUrl": "https://localhost:7040;http://localhost:5143;",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}

View File

@@ -16,103 +16,104 @@
</div>
<div>
<h3>Settings</h3>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
@Html.AntiForgeryToken()
@* @using (Html.BeginForm("Index", "Home", FormMethod.Post)) *@
@* { *@
@* @Html.AntiForgeryToken() *@
<form enctype="multipart/form-data" asp-controller="Home" asp-action="Index" method="post">
<div>
<div>
@Html.LabelFor(model => model.Settings.StartYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.StartYear)
@Html.ValidationMessageFor(model => model.Settings.StartYear, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.StartYear, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.Years, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Years)
@Html.ValidationMessageFor(model => model.Settings.Years, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.Years, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.StartTurnover, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.StartTurnover)
@Html.ValidationMessageFor(model => model.Settings.StartTurnover, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.StartTurnover, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.MaxDiff, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MaxDiff)
@Html.ValidationMessageFor(model => model.Settings.MaxDiff, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.MaxDiff, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.MinDiff, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MinDiff)
@Html.ValidationMessageFor(model => model.Settings.MinDiff, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.MinDiff, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.RSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.RSmoothing)
@Html.ValidationMessageFor(model => model.Settings.RSmoothing, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.RSmoothing, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.MaxSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MaxSmoothing)
@Html.ValidationMessageFor(model => model.Settings.MaxSmoothing, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.MaxSmoothing, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.MinSmoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.MinSmoothing)
@Html.ValidationMessageFor(model => model.Settings.MinSmoothing, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.MinSmoothing, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.Smoothing, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Smoothing)
@Html.ValidationMessageFor(model => model.Settings.Smoothing, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.Smoothing, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.Linear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.Linear)
@Html.ValidationMessageFor(model => model.Settings.Linear, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.Linear, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.HasSin, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.HasSin)
@Html.ValidationMessageFor(model => model.Settings.HasSin, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.HasSin, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.SinLength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinLength)
@Html.ValidationMessageFor(model => model.Settings.SinLength, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.SinLength, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.SinStrength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinStrength)
@Html.ValidationMessageFor(model => model.Settings.SinStrength, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.SinStrength, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.SinNegative, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.SinNegative)
@Html.ValidationMessageFor(model => model.Settings.SinNegative, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.SinNegative, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.HasPeak, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.HasPeak)
@Html.ValidationMessageFor(model => model.Settings.HasPeak, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.HasPeak, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.PeakLength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakLength)
@Html.ValidationMessageFor(model => model.Settings.PeakLength, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.PeakLength, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.PeakStrength, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakStrength)
@Html.ValidationMessageFor(model => model.Settings.PeakStrength, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.PeakStrength, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.RPeakInYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.RPeakInYear)
@Html.ValidationMessageFor(model => model.Settings.RPeakInYear, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.RPeakInYear, "", new {@class = "text-danger"})
</div>
<div>
@Html.LabelFor(model => model.Settings.PeakInYear, new {@class = "control-label col-md-1"}) @Html.EditorFor(model => model.Settings.PeakInYear)
@Html.ValidationMessageFor(model => model.Settings.PeakInYear, "",new {@class = "text-danger"})
@Html.ValidationMessageFor(model => model.Settings.PeakInYear, "", new {@class = "text-danger"})
</div>
</div>
@@ -120,12 +121,18 @@
<div>
<button type="submit" class="btn btn-primary" name="cmd" value="generate">Generate New</button>
<button type="submit" class="btn btn-primary" name="cmd" value="save">Save</button>
<div>
<button type="submit" class="btn btn-primary" name="cmd" value="upload">Upload</button>
<input type="file" name="file" class="btn"/>
</div>
</div>
<input type="hidden" id="Sql" name="Sql" value="@Model.Sql"/>
<input type="hidden" id="DataSet" name="DataSet" value="@Model.DataSet"/>
<input type="hidden" id="LabelSet" name="LabelSet" value="@Model.LabelSet"/>
}
</form>
@*}*@
</div>
<script type="text/javascript">