From e7ee8702984bf92575b71c78da5639a39ff43c10 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Mon, 14 Mar 2022 14:44:08 +0200 Subject: [PATCH] docs: add comments to `DynamicMemory.LD_24` --- DynamicMemory/LD_24/Code/InOutUtils.cs | 59 +++++++++++++++++++++++ DynamicMemory/LD_24/Code/Order.cs | 15 ++++++ DynamicMemory/LD_24/Code/OrderList.cs | 18 +++++++ DynamicMemory/LD_24/Code/Product.cs | 6 --- DynamicMemory/LD_24/Code/ProductList.cs | 15 ++++++ DynamicMemory/LD_24/Code/TaskUtils.cs | 62 ++++++++++++++++++------- DynamicMemory/LD_24/Forma1.aspx.cs | 4 +- DynamicMemory/LD_24/Forma1Utils.aspx.cs | 38 +++++++++++---- DynamicMemory/LD_24/LD_24.csproj | 3 ++ 9 files changed, 188 insertions(+), 32 deletions(-) diff --git a/DynamicMemory/LD_24/Code/InOutUtils.cs b/DynamicMemory/LD_24/Code/InOutUtils.cs index 8f9a4f0..adab74b 100644 --- a/DynamicMemory/LD_24/Code/InOutUtils.cs +++ b/DynamicMemory/LD_24/Code/InOutUtils.cs @@ -8,8 +8,16 @@ using System.Web; namespace LD_24.Code { + /// + /// Class used for reading and writing to files + /// public static class InOutUtils { + /// + /// Read lines from a file + /// + /// Target filename + /// IEnumerable of all the lines private static IEnumerable ReadLines(string filename) { using (StreamReader reader = File.OpenText(filename)) @@ -21,6 +29,12 @@ namespace LD_24.Code } } } + + /// + /// Read products from a file + /// + /// Target file + /// A list of products public static ProductList ReadProducts(string filename) { ProductList products = new ProductList(); @@ -35,6 +49,11 @@ namespace LD_24.Code return products; } + /// + /// Read orders from a file + /// + /// Target file + /// A list of orders public static OrderList ReadOrders(string filename) { OrderList orders = new OrderList(); @@ -50,6 +69,12 @@ namespace LD_24.Code return orders; } + /// + /// Print a single table row to file + /// + /// Target file + /// Cell data + /// Cell widths private static void PrintTableRow(StreamWriter writer, List cells, List widths) { for (int i = 0; i < widths.Count; i++) @@ -62,6 +87,14 @@ namespace LD_24.Code writer.WriteLine("|"); } + /// + /// Print a table to a file + /// + /// Target file + /// Header above table + /// Target list + /// Column names + /// A IEnumerable for inserting values for each row private static IEnumerable>> PrintTable(StreamWriter writer, string header, IEnumerable list, params string[] columns) { // 0. Collect all the rows @@ -128,6 +161,12 @@ namespace LD_24.Code writer.WriteLine(); } + /// + /// Print orders table to file + /// + /// Target file + /// List of orders + /// Header above table public static void PrintOrders(StreamWriter writer, OrderList orders, string header) { foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaisas", "-Įtaiso kiekis")) @@ -141,6 +180,13 @@ namespace LD_24.Code } } + /// + /// Print orders with prices table to file + /// + /// Target file + /// List of orders + /// List of products + /// Header above table public static void PrintOrdersWithPrices(StreamWriter writer, OrderList orders, ProductList products, string header) { foreach (var tuple in PrintTable(writer, header, orders, "Pavardė", "Vardas", "-Įtaiso kiekis, vnt.", "-Kaina, eur.")) @@ -156,6 +202,12 @@ namespace LD_24.Code } } + /// + /// Print a products table to file + /// + /// Target file + /// List of products + /// Header above table public static void PrintProducts(StreamWriter writer, ProductList products, string header) { foreach (var tuple in PrintTable(writer, header, products, "ID", "Vardas", "-Kaina")) @@ -168,6 +220,13 @@ namespace LD_24.Code } } + /// + /// Print a table of most popular products to file + /// + /// Target file + /// List of orders + /// List of most popular products + /// Header above table public static void PrintMostPopularProducts(StreamWriter writer, OrderList orders, ProductList popularProducts, string header) { foreach (var tuple in PrintTable(writer, header, popularProducts, "ID", "Vardas", "-Įtaisų kiekis, vnt.", "-Įtaisų kaina, eur.")) diff --git a/DynamicMemory/LD_24/Code/Order.cs b/DynamicMemory/LD_24/Code/Order.cs index fda1d89..1931ccd 100644 --- a/DynamicMemory/LD_24/Code/Order.cs +++ b/DynamicMemory/LD_24/Code/Order.cs @@ -5,11 +5,26 @@ using System.Web; namespace LD_24.Code { + /// + /// Class used for storing a single order + /// public class Order { + /// + /// Surname of customer who ordered + /// public string CustomerSurname { get; set; } + /// + /// Name of customer who ordered + /// public string CustomerName { get; set; } + /// + /// ID of ordered product + /// public string ProductID { get; set; } + /// + /// Amount of ordered products + /// public int ProductAmount { get; set; } public Order(string customerSurname, string customerName, string productID, int productAmount) diff --git a/DynamicMemory/LD_24/Code/OrderList.cs b/DynamicMemory/LD_24/Code/OrderList.cs index 488bedd..9e04ab2 100644 --- a/DynamicMemory/LD_24/Code/OrderList.cs +++ b/DynamicMemory/LD_24/Code/OrderList.cs @@ -6,6 +6,9 @@ using System.Web; namespace LD_24.Code { + /// + /// Stores a orders in a linked list + /// public class OrderList : IEnumerable { class OrderNode @@ -23,6 +26,10 @@ namespace LD_24.Code private OrderNode head; private OrderNode tail; + /// + /// Append a value to the end of the linked list + /// + /// public void AddToEnd(Order customer) { OrderNode node = new OrderNode(customer); @@ -38,6 +45,10 @@ namespace LD_24.Code } } + /// + /// Insert a value to the start of the linked list + /// + /// public void AddToStart(Order customer) { OrderNode node = new OrderNode(customer); @@ -53,6 +64,10 @@ namespace LD_24.Code } } + /// + /// Get the number of values stored in linked list + /// + /// A count public int Count() { int count = 0; @@ -65,6 +80,9 @@ namespace LD_24.Code return count; } + /// + /// Sorts the linked list + /// public void Sort() { for (OrderNode nodeA = head; nodeA != null; nodeA = nodeA.Next) diff --git a/DynamicMemory/LD_24/Code/Product.cs b/DynamicMemory/LD_24/Code/Product.cs index 8093c0e..d2ad1bc 100644 --- a/DynamicMemory/LD_24/Code/Product.cs +++ b/DynamicMemory/LD_24/Code/Product.cs @@ -23,12 +23,6 @@ namespace LD_24.Code /// public decimal Price { get; set; } - /// - /// Constructs a new product - /// - /// - /// - /// public Product(string iD, string name, decimal price) { ID = iD; diff --git a/DynamicMemory/LD_24/Code/ProductList.cs b/DynamicMemory/LD_24/Code/ProductList.cs index 23962eb..db56384 100644 --- a/DynamicMemory/LD_24/Code/ProductList.cs +++ b/DynamicMemory/LD_24/Code/ProductList.cs @@ -6,6 +6,9 @@ using System.Web; namespace LD_24.Code { + /// + /// Stores multiple products in a linked list + /// public class ProductList : IEnumerable { class ProductNode @@ -23,6 +26,10 @@ namespace LD_24.Code private ProductNode head; private ProductNode tail; + /// + /// Append a value to the end of the linked list + /// + /// public void AddToEnd(Product product) { ProductNode node = new ProductNode(product); @@ -38,6 +45,10 @@ namespace LD_24.Code } } + /// + /// Inserts a value to the start of the linked list + /// + /// public void AddToStart(Product product) { ProductNode node = new ProductNode(product); @@ -53,6 +64,10 @@ namespace LD_24.Code } } + /// + /// Get the number of values stored in the linked list + /// + /// A count public int Count() { int count = 0; diff --git a/DynamicMemory/LD_24/Code/TaskUtils.cs b/DynamicMemory/LD_24/Code/TaskUtils.cs index c33d190..41262fe 100644 --- a/DynamicMemory/LD_24/Code/TaskUtils.cs +++ b/DynamicMemory/LD_24/Code/TaskUtils.cs @@ -6,8 +6,16 @@ using System.Web; namespace LD_24.Code { + /// + /// Various functions for operations on data + /// public static class TaskUtils { + /// + /// Finds the most popular products by the number of sales + /// + /// List of orders + /// List of products ids public static List FindMostPopularProducts(OrderList orders) { Dictionary productSales = new Dictionary(); @@ -41,6 +49,12 @@ namespace LD_24.Code return mostPopularProducts; } + /// + /// Counts the number of sales of a certain product + /// + /// List of products + /// Target product id + /// Sales public static int CountProductSales(OrderList orders, string product) { int sales = 0; @@ -54,19 +68,11 @@ namespace LD_24.Code return sales; } - public static OrderList FilterByProduct(OrderList orders, string product) - { - OrderList filtered = new OrderList(); - foreach (Order order in orders) - { - if (order.ProductID == product) - { - filtered.AddToEnd(order); - } - } - return filtered; - } - + /// + /// Merge orders which have the same customer name, surname and product id into a single order. + /// + /// A list of orders + /// A list of orders where same orders have been merged public static OrderList MergeOrders(OrderList orders) { Dictionary, Order> ordersByName = new Dictionary, Order>(); @@ -90,6 +96,12 @@ namespace LD_24.Code return mergedOrders; } + /// + /// Finds a product by it's id + /// + /// List of products + /// Target product id + /// The product public static Product FindByID(ProductList products, string id) { foreach (Product product in products) @@ -102,6 +114,12 @@ namespace LD_24.Code return null; } + /// + /// Find all products by their ids + /// + /// List of products + /// List of product ids + /// List of products public static ProductList FindByID(ProductList products, List ids) { ProductList foundProducts = new ProductList(); @@ -112,14 +130,22 @@ namespace LD_24.Code return foundProducts; } - public static ProductList FilterByQuantitySoldAndPrice(ProductList products, OrderList customers, int minSold, decimal maxPrice) + /// + /// Filter a list of products by sales and price. + /// + /// List of products + /// List of orders + /// Minimmum sales amount + /// Max product price + /// A list of filtered products + public static ProductList FilterByQuantitySoldAndPrice(ProductList products, OrderList orders, int minSold, decimal maxPrice) { ProductList filtered = new ProductList(); foreach (Product product in products) { if (product.Price < maxPrice) { - int sold = CountProductSales(customers, product.ID); + int sold = CountProductSales(orders, product.ID); if (sold >= minSold) { filtered.AddToEnd(product); @@ -129,6 +155,11 @@ namespace LD_24.Code return filtered; } + /// + /// Find all customer which bought only 1 type of product + /// + /// List of orders + /// A list of filtered orders public static OrderList FindCustomerWithSingleProduct(OrderList orders) { Dictionary, OrderList> ordersByCusomer = new Dictionary, OrderList>(); @@ -152,6 +183,5 @@ namespace LD_24.Code } return finalList; } - } } diff --git a/DynamicMemory/LD_24/Forma1.aspx.cs b/DynamicMemory/LD_24/Forma1.aspx.cs index 9a0b4ad..f9ee37a 100644 --- a/DynamicMemory/LD_24/Forma1.aspx.cs +++ b/DynamicMemory/LD_24/Forma1.aspx.cs @@ -9,9 +9,11 @@ using LD_24.Code; namespace LD_24 { + /// + /// Main form + /// public partial class Forma1 : System.Web.UI.Page { - private const string targetProductID = "1"; private const string inputFileA = "App_Data/U24a.txt"; private const string inputFileB = "App_Data/U24b.txt"; private const string outputFilename = "App_Data/Rezultatai.txt"; diff --git a/DynamicMemory/LD_24/Forma1Utils.aspx.cs b/DynamicMemory/LD_24/Forma1Utils.aspx.cs index 18b98df..f36f09e 100644 --- a/DynamicMemory/LD_24/Forma1Utils.aspx.cs +++ b/DynamicMemory/LD_24/Forma1Utils.aspx.cs @@ -11,6 +11,13 @@ namespace LD_24 { public partial class Forma1 : System.Web.UI.Page { + /// + /// Show a list in a table + /// + /// Target table + /// Target list + /// Columns names + /// private IEnumerable> ShowTable(Table table, IEnumerable list, params string[] columns) { TableRow header = new TableRow(); @@ -37,15 +44,11 @@ namespace LD_24 } } - private IEnumerable> ShowTable(Table table, string title, IEnumerable list, params string[] columns) - { - TableRow row = new TableRow(); - row.Cells.Add(new TableCell { Text = title, ColumnSpan = columns.Length }); - table.Rows.Add(row); - - return ShowTable(table, list, columns); - } - + /// + /// Show a list of products in a table + /// + /// Target table + /// Target products public void ShowProducts(Table table, ProductList products) { foreach (var tuple in ShowTable(table, products, "ID", "Vardas", "Kaina, eur.")) @@ -58,6 +61,11 @@ namespace LD_24 } } + /// + /// Show a list of orders in a table + /// + /// Target table + /// Target orders public void ShowOrders(Table table, OrderList orders) { foreach (var tuple in ShowTable(table, orders, "Pavardė", "Vardas", "Įtaisas", "Įtaisų kiekis, vnt.")) @@ -71,6 +79,12 @@ namespace LD_24 } } + /// + /// Show the most popular products in a table + /// + /// Target table + /// Target orders + /// List of most popular products public void ShowMostPopularProducts(Table table, OrderList orders, ProductList popularProducts) { foreach (var tuple in ShowTable(table, popularProducts, "ID", "Vardas", "Įtaisų kiekis, vnt.", "Įtaisų kaina, eur.")) @@ -85,6 +99,12 @@ namespace LD_24 } } + /// + /// Show a list of orders with their prices in a table + /// + /// Target table + /// Target orders + /// List of products public void ShowOrdersWithPrices(Table table, OrderList orders, ProductList products) { foreach (var tuple in ShowTable(table, orders, "Pavardė", "Vardas", "Įtaisų kiekis, vnt.", "Sumokėta, eur.")) diff --git a/DynamicMemory/LD_24/LD_24.csproj b/DynamicMemory/LD_24/LD_24.csproj index 5021c7f..f6d1e7f 100644 --- a/DynamicMemory/LD_24/LD_24.csproj +++ b/DynamicMemory/LD_24/LD_24.csproj @@ -76,6 +76,9 @@ + + +