= преди 5 месеца
родител
ревизия
ded02d9ef2

BIN
beta/data/prun-data.sqlite


Файловите разлики са ограничени, защото са твърде много
+ 0 - 0
beta/main.js


+ 2 - 2
beta/src/graphs/companyHistory.ts

@@ -39,11 +39,11 @@ export class CompanyHistory implements Graph {
         var companyData: any[];
         if(configValues.metric == 'bases')
         {
-            companyData = await query("SELECT ci.username, bi.bases, bi.month FROM BaseInfo bi LEFT JOIN CompanyInfo ci ON ci.id = bi.id WHERE LOWER(ci.username) = LOWER('" + configValues.companyName + "')")
+            companyData = await query("SELECT ci.username, bi.bases, bi.month FROM BaseInfo bi LEFT JOIN CompanyInfo ci ON ci.id = bi.id WHERE ci.usernamelower = '" + (configValues.companyName).toLowerCase() + "'")
         }
         else
         {
-            companyData = await query("SELECT ci.username, tcd." + configValues.metric + ", tcd.month FROM TotalCompanyProd tcd LEFT JOIN CompanyInfo ci on ci.id = tcd.id WHERE LOWER(ci.username) = LOWER('" + configValues.companyName + "')")
+            companyData = await query("SELECT ci.username, tcd." + configValues.metric + ", tcd.month FROM TotalCompanyProd tcd LEFT JOIN CompanyInfo ci on ci.id = tcd.id WHERE ci.usernamelower = '" + (configValues.companyName).toLowerCase() + "'")
         }
         companyData.sort(monthSort)
 

+ 11 - 19
beta/src/graphs/companyTotals.ts

@@ -1,6 +1,6 @@
 import { createGraph, switchPlot } from "../core";
 import { materialCategoryColors, months, monthsPretty, prettyModeNames } from "../staticData/constants";
-import { addConfigField, clearChildren, getCompanyId, getData, getMatCategory, getMatColor, prettyMonthName } from "../utils";
+import { addConfigField, clearChildren, getCompanyId, getData, getMatCategory, getMatColor, prettyMonthName, query } from "../utils";
 import { Graph } from "./graph";
 
 export class CompanyTotals implements Graph {
@@ -36,28 +36,21 @@ export class CompanyTotals implements Graph {
     async generatePlot(configValues: any, plotContainerID: string)
     {
         if(!configValues.companyName || configValues.companyName == ""){return;}
-        // Get Company Data
-        const companyData = await getData(this.loadedData, "company", configValues.month);
-        const knownCompanies = await getData(this.loadedData, "knownCompanies");
-
-        // Get Company ID
-        var companyID = await getCompanyId(configValues.companyName, this.loadedData) as string;
-        if(!companyID){ return; }
-        var companyName = knownCompanies[companyID];
-
-        if(!companyData.individual[companyID]){return;}
+        
+        const companyData = await query("SELECT icp.ticker, icp." + configValues.metric + " FROM IndivCompanyProd icp LEFT JOIN CompanyInfo ci on ci.id = icp.id WHERE ci.usernamelower = '" + (configValues.companyName).toLowerCase() + "' AND icp.month = '" + configValues.month + "'")
+        
         // Parse Data
         var catData = [] as number[]; // Y-axis of chart
         var categories = [] as any[];  // X-axis of chart
         var totalValue = 0; // Total of metric
-        Object.keys(companyData.individual[companyID]).forEach((ticker: string) => {
-            const metric = companyData.individual[companyID][ticker][configValues.metric];
+        companyData.forEach((data: any) => {
+            const metric = data[configValues.metric];
             if(metric < 0 && (configValues.chartType == "treemap" || configValues.chartType == "treemap-categories")){return;}
             totalValue += metric;
 
             if(configValues.chartType == "treemap-categories")
             {
-                const category = getMatCategory(ticker);
+                const category = getMatCategory(data.ticker);
                 
                 const catIndex = categories.indexOf(category);
                 if(catIndex == -1)
@@ -73,10 +66,9 @@ export class CompanyTotals implements Graph {
             else
             {
                 catData.push(metric);
-                categories.push(ticker);
+                categories.push(data.ticker);
             }
         });
-
         // Sort data from largest to smallest categories
         const indices = Array.from(categories.keys());
         indices.sort((a, b) => catData[b] - catData[a]);
@@ -138,7 +130,7 @@ export class CompanyTotals implements Graph {
                     t: 40,  // top
                     b: 10   // bottom
                 }} : {}),
-                title: {text: titles[configValues.metric] + companyName + ' - ' + prettyMonthName(configValues.month)}
+                title: {text: titles[configValues.metric] + configValues.companyName + ' - ' + prettyMonthName(configValues.month)}
             }, {})
         }
         else if(configValues.chartType == "bar")
@@ -155,7 +147,7 @@ export class CompanyTotals implements Graph {
                         t: 40,  // top
                         b: 60   // bottom
                     }} : {}),
-                    title: {text: titles[configValues.metric] + companyName + ' - ' + prettyMonthName(configValues.month)},
+                    title: {text: titles[configValues.metric] + configValues.companyName + ' - ' + prettyMonthName(configValues.month)},
                     xaxis: {
                         title: {text: 'Ticker'},
                         range: [-0.5, Math.min(categories.length, 30) - 0.5]
@@ -180,7 +172,7 @@ export class CompanyTotals implements Graph {
                         t: 40,  // top
                         b: 10   // bottom
                     }} : {}),
-                    title: {text: titles[configValues.metric] + companyName + ' - ' + prettyMonthName(configValues.month)},
+                    title: {text: titles[configValues.metric] + configValues.companyName + ' - ' + prettyMonthName(configValues.month)},
                     xaxis: {
                         title: {text: 'Ticker'},
                         range: [-0.5, Math.min(categories.length, 30) - 0.5]

+ 9 - 16
beta/src/graphs/marketOverview.ts

@@ -1,6 +1,6 @@
 import { createGraph, switchPlot } from "../core";
 import { months, monthsPretty } from "../staticData/constants";
-import { addConfigField, clearChildren, getData, prettyMonthName } from "../utils";
+import { addConfigField, clearChildren, getData, prettyMonthName, query } from "../utils";
 import { Graph } from "./graph";
 
 export class MarketOverview implements Graph {
@@ -36,9 +36,7 @@ export class MarketOverview implements Graph {
         if (!ticker) {
             return;
         }
-
-        const companyData = await getData(this.loadedData, "company", configValues.month);
-        const knownCompanies = await getData(this.loadedData, "knownCompanies");
+        const companyData = await query("SELECT COALESCE(ci.username, CONCAT(SUBSTR(icp.id, 1, 5), '...')) username, icp.volume, icp.profit, icp.amount FROM IndivCompanyProd icp LEFT JOIN CompanyInfo ci on ci.id = icp.id WHERE icp.ticker = '" + ticker + "' AND icp.month = '" + configValues.month + "'")
 
         const labels = [] as string[];
         const parents = [] as string[];
@@ -46,18 +44,13 @@ export class MarketOverview implements Graph {
         let totalAmount = 0;
         let totalVolume = 0;
         let totalProfit = 0;
-        for (const key of Object.keys(companyData.individual)) {
-            const individualData = companyData.individual[key];
-            const tickerData = individualData[ticker];
-            if (!tickerData) {
-                continue;
-            }
-            labels.push(knownCompanies[key] ?? (key.substring(0, 5) + "..."));
+        for (const company of companyData) {
+            labels.push(company.username);
             parents.push("Total");
-            values.push(tickerData.amount);
-            totalVolume += tickerData.volume;
-            totalProfit += tickerData.profit;
-            totalAmount += tickerData.amount;
+            values.push(company.amount);
+            totalVolume += company.volume;
+            totalProfit += company.profit;
+            totalAmount += company.amount;
         }
 
         if (labels.length === 0) {
@@ -74,7 +67,7 @@ export class MarketOverview implements Graph {
             + `Produced per day: ${Math.round(totalAmount).toLocaleString()} ${ticker}`
             + "<br>"
             + `Volume: ${formatMoney(totalVolume)} | Profit: ${formatMoney(totalProfit)}`;
-
+            
         // Create graph
         createGraph(plotContainerID, [{
                 labels: labels,

+ 18 - 37
beta/src/graphs/matHistory.ts

@@ -1,6 +1,6 @@
 import { createGraph, switchPlot } from "../core";
-import { months, monthsPretty } from "../staticData/constants";
-import { addConfigField, clearChildren, getData, prettyMonthName } from "../utils";
+import { monthsPrettyMap } from "../staticData/constants";
+import { addConfigField, clearChildren, monthSort, query } from "../utils";
 import { Graph } from "./graph";
 
 export class MatHistory implements Graph {
@@ -34,45 +34,26 @@ export class MatHistory implements Graph {
     async generatePlot(configValues: any, plotContainerID: string)
     {
         if(!configValues.ticker || configValues.ticker == ""){return;}
+        const ticker = configValues.ticker ? (configValues.ticker).toUpperCase() : undefined
 
         // Get Data
-        const totalTickerData = [];
-        for(var i = 0; i < months.length; i++)
+        var prodData: any[]
+        switch(configValues.metric)
         {
-            const monthData = await getData(this.loadedData, "prod", months[i]);
-            totalTickerData.push(monthData[(configValues.ticker ?? "").toUpperCase()])
+            case 'price':
+                prodData = await query("SELECT CASE WHEN amount = 0 THEN 0 ELSE volume/amount END price, month FROM ProdInfo WHERE ticker = '" + ticker + "'")
+                break;
+            case 'surplus':
+                prodData = await query("SELECT amount - consumed surplus, month FROM ProdInfo WHERE ticker = '" + ticker + "'")
+                break;
+            default:
+                prodData = await query("SELECT " + configValues.metric + ", month FROM ProdInfo WHERE ticker = '" + ticker + "'")
+        
         }
+        prodData.sort(monthSort)
         
-        const tickerData = [] as number[];  // Data for the specific metric
-        const validMonths = [] as string[]; // Months with data
-        totalTickerData.forEach((data, i) => {
-            if(!data){return;}
-            validMonths.push(monthsPretty[i]);
-
-            switch(configValues.metric)
-            {
-                case "volume":
-                    tickerData.push(data.volume);
-                    break;
-                case "profit":
-                    tickerData.push(data.profit);
-                    break;
-                case "price":
-                    tickerData.push(data.amount == 0 ? 0 : data.volume / data.amount);
-                    break;
-                case "amount":
-                    tickerData.push(data.amount);
-                    break;
-                case "consumed":
-                    tickerData.push(data.consumed);
-                    break;
-                case "surplus":
-                    tickerData.push(data.amount - data.consumed);
-                    break;
-            }
-        });
-
-        if(validMonths.length == 0){return;}
+        const months = prodData.map(item => monthsPrettyMap[item.month]);
+        const prodArray = prodData.map(item => item[configValues.metric])
 
         const titles = {
             'profit': 'Production Profit History of ',
@@ -92,7 +73,7 @@ export class MatHistory implements Graph {
         } as any
 
         // Create graph
-        createGraph(plotContainerID, [{x: validMonths, y: tickerData, type: 'bar'}], 
+        createGraph(plotContainerID, [{x: months, y: prodArray, type: 'bar'}], 
             {
                 width: this.urlParams.hideOptions !== undefined ? undefined : 800,
                 height: this.urlParams.hideOptions !== undefined ? undefined : 400,

+ 22 - 19
beta/src/graphs/topCompanies.ts

@@ -1,6 +1,6 @@
 import { createGraph, switchPlot } from "../core";
 import { months, monthsPretty, prettyModeNames } from "../staticData/constants";
-import { addConfigField, clearChildren, getData, prettyMonthName } from "../utils";
+import { addConfigField, clearChildren, getData, prettyMonthName, query } from "../utils";
 import { Graph } from "./graph";
 
 export class TopCompanies implements Graph {
@@ -33,28 +33,31 @@ export class TopCompanies implements Graph {
 
     async generatePlot(configValues: any, plotContainerID: string)
     {
+        
         // Get Data
-        const companyData = await getData(this.loadedData, configValues.metric == "bases" ? "base" : "company", configValues.month);
-        const knownCompanies = await getData(this.loadedData, "knownCompanies");
+        var companyData: any[];
+        if(configValues.metric == 'bases')
+        {
+            companyData = await query("SELECT COALESCE(ci.username, bi.id, bi.bases FROM BaseInfo bi LEFT JOIN CompanyInfo ci ON ci.id = bi.id WHERE bi.month = '" + configValues.month + "'")
+            companyData.forEach(data => {
+                data.username = data.username ?? data.id.slice(0, 5) + '...' 
+            });
+        }
+        else
+        {
+            companyData = await query("SELECT ci.username, tcd.id, tcd." + configValues.metric + " FROM TotalCompanyProd tcd LEFT JOIN CompanyInfo ci on ci.id = tcd.id WHERE tcd.month = '" + configValues.month + "'")
+            companyData.forEach(data => {
+                data.username = data.username ?? data.id.slice(0, 5) + '...' 
+            });
+        }
         
-        // Convert the data object into an array of [companyID, volume] pairs
-        const volumeArray = Object.entries(configValues.metric == "bases" ? companyData : companyData.totals).map(([companyID, info]) => ({
-            companyID,
-            volume: (info as any)[configValues.metric]
-        }));
-
-        // Sort the array by volume in descending order
-        volumeArray.sort((a, b) => b.volume - a.volume);
+        // Sort the array by metric in descending order
+        companyData.sort((a, b) => b[configValues.metric] - a[configValues.metric]);
 
         // Extract tickers and volumes into separate arrays
-        const companyIDs = volumeArray.map(item => item.companyID);
-        const volumes = volumeArray.map(item => item.volume);
-
-        const companyNames = [] as any[];
-        companyIDs.forEach(id => {
-            companyNames.push(knownCompanies[id] || (id.slice(0, 5) + "..."));
-        });
-
+        const companyNames = companyData.map(item => item.username);
+        const volumes = companyData.map(item => item[configValues.metric]);
+        
         // Create graph
         createGraph(plotContainerID, [{x: companyNames, y: volumes, type: 'bar'}], 
             {

+ 7 - 3
beta/src/utils.ts

@@ -6,6 +6,7 @@ var SQL: any;
 var db: any;
 export async function query(sqlQuery: string)
 {
+	console.log(sqlQuery)
 	if(!SQL)
 	{
 		SQL = await initSqlJs({
@@ -13,20 +14,23 @@ export async function query(sqlQuery: string)
 				"./sql-wasm.wasm"
 		});
 		
-		const buffer = await fetch("./data/prun-data.sqlite").then(r => r.arrayBuffer());
+		const buffer = await fetch(`./data/prun-data.sqlite?ts=${Date.now()}`).then(r => r.arrayBuffer());
 
 		db = new SQL.Database(new Uint8Array(buffer));
 		
 	}
 
-    const result = db.exec(sqlQuery);
+    console.time("exec");
+	const result = db.exec(sqlQuery);
+	console.timeEnd("exec");
 	if (!result || result.length === 0) return [];
 
 	const { columns, values } = result[0];
 
-	return values.map((row: any[]) =>
+	const x = values.map((row: any[]) =>
 		Object.fromEntries(row.map((val, i) => [columns[i], val]))
 	);
+	return x
 }
 
 // Sort an array by the key of each object month

Някои файлове не бяха показани, защото твърде много файлове са промени