feat: add file upload of initial data
This commit is contained in:
parent
4354e33d59
commit
c9eba7336c
@ -1,45 +1,45 @@
|
||||
----------------------------
|
||||
| Įtaisai |
|
||||
----------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
| ID | Vardas | Kaina |
|
||||
----------------------------
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
| 2 | Laidas | 2.00 |
|
||||
| 3 | Plaktukas | 2.99 |
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
| 2 | Laidas | 2.00 |
|
||||
| 3 | Plaktukas | 2.99 |
|
||||
----------------------------
|
||||
|
||||
--------------------------------------------------
|
||||
| Pirkėjai |
|
||||
--------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
|
||||
| Pavardė | Vardas | Įtaisas | Įtaiso kiekis |
|
||||
--------------------------------------------------
|
||||
| Petraitis | Petras | 0 | 10 |
|
||||
| Petraitis | Petras | 1 | 10 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Onaite | Ona | 2 | 200 |
|
||||
| Jonaitis | Brolis | 1 | 100 |
|
||||
| Jonaitis | Brolis | 0 | 100 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 2 | 20 |
|
||||
| Onaite | Ona | 0 | 20 |
|
||||
| Petraitis | Petras | 0 | 10 |
|
||||
| Petraitis | Petras | 1 | 10 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Onaite | Ona | 2 | 200 |
|
||||
| Jonaitis | Brolis | 1 | 100 |
|
||||
| Jonaitis | Brolis | 0 | 100 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 1 | 20 |
|
||||
| Jonaitis | Jonas | 2 | 20 |
|
||||
| Onaite | Ona | 0 | 20 |
|
||||
--------------------------------------------------
|
||||
|
||||
------------------------------------------------------------
|
||||
| Populiariausi įtaisai |
|
||||
------------------------------------------------------------
|
||||
| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
|
||||
| ID | Vardas | Įtaisų kiekis, vnt. | Įtaisų kaina, eur. |
|
||||
------------------------------------------------------------
|
||||
| 2 | Laidas | 220 | 440.00 |
|
||||
| 2 | Laidas | 220 | 440.00 |
|
||||
------------------------------------------------------------
|
||||
|
||||
----------------------------------------------------------
|
||||
| Vienos rūšies pirkėjai |
|
||||
----------------------------------------------------------
|
||||
| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
|
||||
| Pavardė | Vardas | Įtaiso kiekis, vnt. | Kaina, eur. |
|
||||
----------------------------------------------------------
|
||||
| Nėra |
|
||||
----------------------------------------------------------
|
||||
@ -47,9 +47,9 @@
|
||||
----------------------------------
|
||||
| Atrinkti įtaisai (n=1, k=1.00) |
|
||||
----------------------------------
|
||||
| ID | Vardas | Kaina |
|
||||
| ID | Vardas | Kaina |
|
||||
----------------------------------
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
| 0 | Atsuktuvas | 0.99 |
|
||||
| 1 | Varztas | 0.05 |
|
||||
----------------------------------
|
||||
|
||||
|
@ -14,31 +14,28 @@ namespace LD_24.Code
|
||||
public static class InOutUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Read lines from a file
|
||||
/// Read lines from a stream
|
||||
/// </summary>
|
||||
/// <param name="filename">Target filename</param>
|
||||
/// <returns>IEnumerable of all the lines</returns>
|
||||
private static IEnumerable<string> ReadLines(string filename)
|
||||
private static IEnumerable<string> ReadLines(StreamReader stream)
|
||||
{
|
||||
using (StreamReader reader = File.OpenText(filename))
|
||||
string line;
|
||||
while ((line = stream.ReadLine()) != null)
|
||||
{
|
||||
string line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
yield return line;
|
||||
}
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read products from a file
|
||||
/// Read products from a stream reader
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <param name="reader">Target stream reader</param>
|
||||
/// <returns>A list of products</returns>
|
||||
public static LinkedList<Product> ReadProducts(string filename)
|
||||
public static LinkedList<Product> ReadProducts(StreamReader reader)
|
||||
{
|
||||
LinkedList<Product> products = new LinkedList<Product>();
|
||||
foreach (string line in ReadLines(filename))
|
||||
foreach (string line in ReadLines(reader))
|
||||
{
|
||||
string[] parts = line.Split(',');
|
||||
string id = parts[0].Trim();
|
||||
@ -49,15 +46,67 @@ namespace LD_24.Code
|
||||
return products;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read products from a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Target stream</param>
|
||||
/// <returns>A list of products</returns>
|
||||
public static LinkedList<Product> ReadProducts(Stream stream)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
return ReadProducts(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read products from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>A list of products</returns>
|
||||
public static LinkedList<Product> ReadProducts(string filename)
|
||||
{
|
||||
using (StreamReader reader = File.OpenText(filename))
|
||||
{
|
||||
return ReadProducts(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read orders from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>A list of orders</returns>
|
||||
public static LinkedList<Order> ReadOrders(string filename)
|
||||
{
|
||||
using (StreamReader reader = File.OpenText(filename))
|
||||
{
|
||||
return ReadOrders(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read orders from a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Target stream</param>
|
||||
/// <returns>A list of orders</returns>
|
||||
public static LinkedList<Order> ReadOrders(Stream stream)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
return ReadOrders(reader);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read orders from a stream reader
|
||||
/// </summary>
|
||||
/// <param name="reader">Target stream reader</param>
|
||||
/// <returns>A list of orders</returns>
|
||||
public static LinkedList<Order> ReadOrders(StreamReader reader)
|
||||
{
|
||||
LinkedList<Order> orders = new LinkedList<Order>();
|
||||
foreach (string line in ReadLines(filename))
|
||||
foreach (string line in ReadLines(reader))
|
||||
{
|
||||
string[] parts = line.Split(',');
|
||||
string customerSurname = parts[0].Trim();
|
||||
@ -79,10 +128,10 @@ namespace LD_24.Code
|
||||
{
|
||||
for (int i = 0; i < widths.Count; i++)
|
||||
{
|
||||
if (widths[i] < 0)
|
||||
writer.Write("| {0} ", cells[i].PadRight(-widths[i]));
|
||||
if (widths[i] > 0)
|
||||
writer.Write("| {0} ", cells[i].PadRight(widths[i]));
|
||||
else
|
||||
writer.Write("| {0} ", cells[i].PadLeft(widths[i]));
|
||||
writer.Write("| {0} ", cells[i].PadLeft(-widths[i]));
|
||||
}
|
||||
writer.WriteLine("|");
|
||||
}
|
||||
|
@ -42,10 +42,8 @@ namespace LD_24.Code
|
||||
public int Count()
|
||||
{
|
||||
int count = 0;
|
||||
Node current = head;
|
||||
while (current != null)
|
||||
for (Node d = head; d != null; d = d.Next)
|
||||
{
|
||||
current = current.Next;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
|
@ -10,15 +10,27 @@
|
||||
<form id="form1" runat="server">
|
||||
|
||||
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" />
|
||||
<asp:Label ID="Label9" runat="server" Text="Produktai:"></asp:Label>
|
||||
<br />
|
||||
<asp:FileUpload ID="FileUpload1" runat="server" />
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1" Display="Dynamic" ErrorMessage="Privaloma nurodyti produktus" ForeColor="Red"></asp:RequiredFieldValidator>
|
||||
<br />
|
||||
<asp:Label ID="Label10" runat="server" Text="Pirkėjai:"></asp:Label>
|
||||
<br />
|
||||
<asp:FileUpload ID="FileUpload2" runat="server" />
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="FileUpload2" Display="Dynamic" ErrorMessage="Privaloma nurodyti pirkėjus" ForeColor="Red"></asp:RequiredFieldValidator>
|
||||
<br />
|
||||
<asp:Label ID="Label5" runat="server" Text="n:"></asp:Label>
|
||||
<br />
|
||||
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
|
||||
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="Tiktais teigiami sveiki skaičiai yra galimi" ForeColor="Red" ValidationExpression="\d+"></asp:RegularExpressionValidator>
|
||||
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage=""n" gali būti tiktais teigiamas sveikas skaičius" ForeColor="Red" ValidationExpression="\d+" Display="Dynamic"></asp:RegularExpressionValidator>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBox1" Display="Dynamic" ErrorMessage="Privaloma nurodyti "n"" ForeColor="Red"></asp:RequiredFieldValidator>
|
||||
<br />
|
||||
<asp:Label ID="Label6" runat="server" Text="k:"></asp:Label>
|
||||
<br />
|
||||
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
|
||||
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="Tiktais teigiami skaičiai yra galimi" ForeColor="Red" ValidationExpression="\d+(\.\d+)?"></asp:RegularExpressionValidator>
|
||||
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage=""k" gali būti tiktais teigiamas sveikas skaičius" ForeColor="Red" ValidationExpression="\d+(\.\d+)?" Display="Dynamic"></asp:RegularExpressionValidator>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox2" Display="Dynamic" ErrorMessage="Privaloma nurodyti "k"" ForeColor="Red"></asp:RequiredFieldValidator>
|
||||
<br />
|
||||
<br />
|
||||
<asp:Button ID="Button1" runat="server" Text="Atrinkti" OnClick="Button1_Click" />
|
||||
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
@ -14,8 +15,6 @@ namespace LD_24
|
||||
/// </summary>
|
||||
public partial class Forma1 : System.Web.UI.Page
|
||||
{
|
||||
private const string inputFileA = "App_Data/U24a.txt";
|
||||
private const string inputFileB = "App_Data/U24b.txt";
|
||||
private const string outputFilename = "App_Data/Rezultatai.txt";
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
@ -30,8 +29,8 @@ namespace LD_24
|
||||
|
||||
FindControl("ResultsDiv").Visible = true;
|
||||
|
||||
var products = InOutUtils.ReadProducts(Server.MapPath(inputFileA));
|
||||
var orders = InOutUtils.ReadOrders(Server.MapPath(inputFileB));
|
||||
var products = InOutUtils.ReadProducts(FileUpload1.FileContent);
|
||||
var orders = InOutUtils.ReadOrders(FileUpload2.FileContent);
|
||||
|
||||
List<string> mostPopularProductIds = TaskUtils.FindMostPopularProducts(orders);
|
||||
var mostPopularProducts = TaskUtils.FindByID(products, mostPopularProductIds);
|
||||
@ -54,5 +53,6 @@ namespace LD_24
|
||||
InOutUtils.PrintProducts(writer, filteredProducts, $"Atrinkti įtaisai (n={n}, k={k:f2})");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
78
L3/LD_24/Forma1.aspx.designer.cs
generated
78
L3/LD_24/Forma1.aspx.designer.cs
generated
@ -7,10 +7,12 @@
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace LD_24 {
|
||||
namespace LD_24
|
||||
{
|
||||
|
||||
|
||||
public partial class Forma1 {
|
||||
public partial class Forma1
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// form1 control.
|
||||
@ -30,6 +32,60 @@ namespace LD_24 {
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
|
||||
|
||||
/// <summary>
|
||||
/// Label9 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label9;
|
||||
|
||||
/// <summary>
|
||||
/// FileUpload1 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.FileUpload FileUpload1;
|
||||
|
||||
/// <summary>
|
||||
/// RequiredFieldValidator1 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
|
||||
|
||||
/// <summary>
|
||||
/// Label10 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Label Label10;
|
||||
|
||||
/// <summary>
|
||||
/// FileUpload2 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.FileUpload FileUpload2;
|
||||
|
||||
/// <summary>
|
||||
/// RequiredFieldValidator2 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
|
||||
|
||||
/// <summary>
|
||||
/// Label5 control.
|
||||
/// </summary>
|
||||
@ -57,6 +113,15 @@ namespace LD_24 {
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
|
||||
|
||||
/// <summary>
|
||||
/// RequiredFieldValidator3 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
|
||||
|
||||
/// <summary>
|
||||
/// Label6 control.
|
||||
/// </summary>
|
||||
@ -84,6 +149,15 @@ namespace LD_24 {
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
|
||||
|
||||
/// <summary>
|
||||
/// RequiredFieldValidator4 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
|
||||
|
||||
/// <summary>
|
||||
/// Button1 control.
|
||||
/// </summary>
|
||||
|
@ -1,14 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FluentAssertions" version="6.5.1" targetFramework="net461" />
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net461" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.5.0" targetFramework="net461" />
|
||||
<package id="xunit" version="2.4.1" targetFramework="net461" />
|
||||
<package id="xunit.abstractions" version="2.0.3" targetFramework="net461" />
|
||||
<package id="xunit.analyzers" version="0.10.0" targetFramework="net461" />
|
||||
<package id="xunit.assert" version="2.4.1" targetFramework="net461" />
|
||||
<package id="xunit.core" version="2.4.1" targetFramework="net461" />
|
||||
<package id="xunit.extensibility.core" version="2.4.1" targetFramework="net461" />
|
||||
<package id="xunit.extensibility.execution" version="2.4.1" targetFramework="net461" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user