Jelajahi Sumber

Remove all of the machine learning stuff for the time being.

Lee Morgan 5 tahun lalu
induk
melakukan
a96d28ade8

+ 0 - 2
views/dashboardPage/dashboard.ejs

@@ -43,7 +43,6 @@
             <% include ./ejs/sidebars/newRecipe %>
             <% include ./ejs/sidebars/orderDetails %>
             <% include ./ejs/sidebars/newOrder %>
-            <% include ./ejs/sidebars/orderCalculator %>
             <% include ./ejs/sidebars/transactionDetails %>
             <% include ./ejs/sidebars/newTransaction %>
             <% include ./ejs/sidebars/editRecipe %>
@@ -54,7 +53,6 @@
         <% include ../shared/loader %>
         <% include ./modal %>
 
-        <script src="https://unpkg.com/ml5@latest/dist/ml5.min.js"></script>
         <script>
             let data = {
                 merchant: <%- JSON.stringify(merchant) %>,

+ 0 - 27
views/dashboardPage/ejs/sidebars/orderCalculator.ejs

@@ -1,27 +0,0 @@
-<div id="orderCalculator">
-    <div class="sidebarIconButtons mobileHide">
-        <button class="iconButton" onclick="controller.closeSidebar()">
-            <svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
-                <line x1="5" y1="12" x2="19" y2="12"></line>
-                <polyline points="12 5 19 12 12 19"></polyline>
-            </svg>
-        </button>
-    </div>
-
-    <h1>ORDER PREDICTION</h1>
-
-    <div class="dateRange">
-        <h3>Date Range:</h3>
-        <div class="dateRangeInput">
-            <input id="predictDateFrom" type="date">
-            <p> - </p>
-            <input id="predictDateTo" type="date">
-        </div>
-    </div>
-
-    <select id="predictSelector"></select>
-
-    <button class="button" id="predictButton">PREDICT</button>
-
-    <h1 id="prediction"></h1>
-</div>

+ 0 - 2
views/dashboardPage/ejs/strands/orders.ejs

@@ -6,8 +6,6 @@
             <button id="orderFilterBtn" class="button">FILTER</button>
 
             <button id="newOrderBtn" class="button">NEW</button>
-
-            <button id="orderCalcBtn" class="button">PREDICTOR</button>
         </div>
     </div>
 

+ 0 - 4
views/dashboardPage/js/dashboard.js

@@ -15,7 +15,6 @@ const editRecipe = require("./sidebars/editRecipe.js");
 const newTransaction = require("./sidebars/newTransaction.js");
 const orderDetails = require("./sidebars/orderDetails.js");
 const orderFilter = require("./sidebars/orderFilter.js");
-const orderCalculator = require("./sidebars/orderCalculator.js");
 const recipeDetails = require("./sidebars/recipeDetails.js");
 const transactionDetails = require("./sidebars/transactionDetails.js");
 const transactionFilter = require("./sidebars/transactionFilter.js");
@@ -126,9 +125,6 @@ controller = {
             case "newOrder":
                 newOrder.display();
                 break;
-            case "orderCalculator":
-                orderCalculator.display();
-                break;
             case "transactionDetails":
                 transactionDetails.display(data);
                 break;

+ 0 - 136
views/dashboardPage/js/sidebars/orderCalculator.js

@@ -1,136 +0,0 @@
-let orderCalculator = {
-    display: function(){
-        let to = new Date();
-        to.setDate(to.getDate() + 7);
-        to.setHours(0, 0, 0, 0);
-        from = new Date();
-        from.setDate(from.getDate() + 1);
-        from.setHours(0, 0, 0, 0);
-
-        document.getElementById("predictDateFrom").valueAsDate = from;
-        document.getElementById("predictDateTo").valueAsDate = to;
-        document.getElementById("predictButton").onclick = ()=>{this.predict()};
-
-        let selector = document.getElementById("predictSelector");
-        while(selector.children.length > 0){
-            selector.removeChild(selector.firstChild);
-        }
-
-        for(let i = 0; i < merchant.ingredients.length; i++){
-            let option = document.createElement("option");
-            option.innerText = merchant.ingredients[i].ingredient.name;
-            option.value = merchant.ingredients[i].ingredient.id;
-            selector.appendChild(option);
-        }
-    },
-
-    predict: function(){
-        let from = document.getElementById("predictDateFrom").valueAsDate;
-        let to = document.getElementById("predictDateTo").valueAsDate;
-        let ingredient = merchant.getIngredient(document.getElementById("predictSelector").value);
-
-        let data = {
-            to: new Date(),
-            recipes: []
-        }
-
-        data.from = new Date(data.to.getFullYear() - 1, data.to.getMonth(), data.to.getDate());
-
-        fetch("/transaction", {
-            method: "post",
-            headers: {
-                "Content-Type": "application/json;charset=utf-8"
-            },
-            body: JSON.stringify(data)
-        })
-            .then(response => response.json())
-            .then((response)=>{
-                if(typeof(response) === "string"){
-                    controller.createBanner(response, "error");
-                }else{
-                    const options = {
-                        task: "regression",
-                        debug: false
-                    }
-
-                    const nn = ml5.neuralNetwork(options);
-
-                    this.createData(nn, response, ingredient.ingredient);
-                    nn.normalizeData();
-                    nn.train(()=>{
-                        let predictors = [];
-                        while(from <= to){
-                            predictors.push(nn.predict({
-                                month: from.getMonth(),
-                                day: from.getDay()
-                            }))
-
-                            from.setDate(from.getDate() + 1);
-                        }
-
-                        Promise.all(predictors)
-                            .then((predictions)=>{
-                                let total = 0
-                                for(let i = 0; i < predictions.length; i++){
-                                    total += predictions[i][0].value;
-                                }
-
-                                if(isNaN(total)) total = 0;
-                                document.getElementById("prediction").innerText = `${total.toFixed(2)} ${ingredient.ingredient.unit.toUpperCase()}`;
-                            })
-                            .catch((err)=>{
-                                controller.createBanner("ERROR: UNABLE TO MAKE PREDICTION", "error");
-                            });
-                    });
-                }
-            })
-            .catch((err)=>{
-                controller.createBanner("ERROR: UNABLE TO MAKE PREDICTION", "error");
-            });
-    },
-
-    createData: function(nn, transactions, ingredient){
-        let today = new Date(transactions[transactions.length-1].date);
-        today.setHours(0, 0, 0, 0);
-        let tomorrow = new Date(transactions[transactions.length-1].date);
-        tomorrow.setDate(tomorrow.getDate() + 1);
-        tomorrow.setHours(0, 0, 0, 0);
-        let dailySum = 0;
-
-        for(let i = transactions.length - 1; i >= 0; i--){
-            transactions[i].date = new Date(transactions[i].date);
-
-            if(transactions[i].date >= tomorrow){
-                let inputs = {
-                    month: today.getMonth(),
-                    day: today.getDay()
-                };
-
-                let output = {quantity: dailySum};
-
-                nn.addData(inputs, output);
-                dailySum = 0;
-                today.setDate(today.getDate() + 1);
-                tomorrow.setDate(tomorrow.getDate() + 1);
-            }
-
-            for(let j = 0; j < transactions[i].recipes.length; j++){
-                for(let k = 0; k < merchant.recipes.length; k++){
-                    if(merchant.recipes[k].id === transactions[i].recipes[j].recipe){
-                        for(let l = 0; l < merchant.recipes[k].ingredients.length; l++){
-                            if(merchant.recipes[k].ingredients[l].ingredient === ingredient){
-                                dailySum += merchant.recipes[k].ingredients[l].quantity * transactions[i].recipes[j].quantity;
-
-                                break;
-                            }
-                        }
-
-                        break;
-                    }
-                }
-            }
-        }
-    }
-}
-
-module.exports = orderCalculator;

+ 0 - 1
views/dashboardPage/js/strands/orders.js

@@ -4,7 +4,6 @@ let orders = {
     display: function(){
         document.getElementById("orderFilterBtn").addEventListener("click", ()=>{controller.openSidebar("orderFilter")});
         document.getElementById("newOrderBtn").addEventListener("click", ()=>{controller.openSidebar("newOrder")});
-        document.getElementById("orderCalcBtn").addEventListener("click", ()=>{controller.openSidebar("orderCalculator")});
 
         if(this.isPopulated === false){
             this.getOrders()