Math isn't really my thing, but what I'm trying to figure out is how to predict/estimate the next number from a dataset.
Let's say I have an array:
var values = new Array(1,4,3,5,6,10,4,15);
Does anyone know a formula in javascript that could guess the next number after 15 based off the previous values in the array.
Basically I have an array of total numbers from daily sales, each item in the array is the total for a single day. So I'd like something that could guess what tomorrow's sale might be.
Based on the data you're providing, it seems you can only predict what tomorrow's sale might be by taking the average of your dataset.
If you had additional data, say, day of the week, you could take the average of all sales on Tuesdays, and then make a prediction based off of that average.
Have a look at the various moving average methods - you can choose whichever suits your application best.
Related
I have an array of strings in this format: "2023-01-30". The dates range from past, to present, to future. I want to sort the dates into separate arrays based on the work weeks (monday through friday) that they fall into with past weeks falling into the present week.
For instance, given the array ["2022-02-15", 2023-01-30", "2023-02-03", "2023-02-06", "2023-02-14"] I want to sort into a 2d array with the first array being this week and all past events, and following arrays being subsequent weeks: [["2022-02-15", 2023-01-30", "2023-02-03"], ["2023-02-06"], ["2023-02-14"]]. I'm trying to use the js Date() object to accomplish this but something in my logic is off. Thanks in advance!
I want to store restaurant's monthly revenue (income and expenses), and later show it on a line graph for every year. I have come to this workaround I would store in year variable for example 2020-01-01 and then it should be adding values to all the following row for every month. Would it even work this way? Or should I use one date type and add months to it?
It can work, but it is not optimal.
For example if you want to see the yearly expenses you have to type every single month name into your query.
A more practical solution can be to use a single table with example columns like so:
date
is_expense (boolean)
amount (double)
restaurant_id
Where is_expense is boolean if the amount is income or expense.
You can aggregate from here everything: yearly / monthly expenses/incomes/profits etc.
You can use MySQL Functions like MONTH(date) that will give you specific month. For example if you want to aggregate all expenses for specific year & month you will do something similar to
SELECT SUM(amount) from Table WHERE is_expense=1 AND MONTH(date) = 1 AND YEAR(date) = 2020
I have a list of bills. I must continuously name them according to my bank accounts.
Normally I would sort my sheet by BANK ACCOUNT and DATE, then tag the NUMBER COLUMN by using the "blue square", and after that, I sort by date again.
I wanna program a script function to iterate through the column NUMBER which defines and read the ACCOUNT column and tag the NUMBER row accordingly.
I thought I make a "settings"-column somewhere to define the look of the "auto-formatter":
IF BANK {YY}-BANK-{NUMBER}
IF CASH {YY}-CASH-{NUMBER}
In the end, it should look like the example below:
DATE NUMBER ACCOUNT
|------|------------|-------|
1. Jan 18-CASH-01 CASH
1. Jan 18-BANK-01 BANK
2. Jan 18-CASH-02 CASH
3. Jan 18-CASH-03 CASH
4. Jan 18-BANK-02 BANK
I made a demo sheet that is free to change or clone.
The basic formula is implemented.
Only the formula to iterate is missing
https://docs.google.com/spreadsheets/d/1aJRqODUMyJai-aVyTj3_konvc8qpL8idKEHNCs9cxSo/edit?usp=sharing
Has anyone a suggestion or starting point for me?
I am not good at google sheets API.
Thank you very much in advance
Maybe this can be done with a formula? In F1 I entered
={"Format"; ArrayFormula(if(len(D2:D), text(C2:C7, "yy")&"-"& UPPER(D2:D)&"-"&iferror(SORT(ROW(D2:D),SORT(ROW(D2:D),D2:D,1),1)-MATCH(D2:D,SORT(D2:D),0)-ROW()+1),))}
See if that works for you?
EDIT, to match the names of the backaccounts to a range, use vlookup
={"Solution A"; ArrayFormula(if(len(D2:D), text(C2:C7, "yy")&"-"&
VLOOKUP(D2:D, SETTINGS!A10:C, 2, 0)&"-
"&iferror(SORT(ROW(D2:D),SORT(ROW(D2:D),D2:D,1),1)-
MATCH(D2:D,SORT(D2:D),0)-ROW()+1),))}
I'm trying to organize a query which should print a count of items ordered by a time unit such as a hour, a day etc.
My limitation is that I'm using LovefieldDB javascript library and complex queries are limited.
I have a table of Units where the main field is the date of creation like this:
2017/11/29 08:17
2017/11/29 08:47
2017/11/29 09:25
2017/11/29 11:39
The result I expect is to count per hour the number of items:
08:00 (2)
09:00 (1)
11:00 (1)
What I want to avoid is to select all rows and process them in a loop because this software is going to have thousands of rows and I'll have to create similar queries for day, month and also year.
A possible solution I thought is to add 4 more datetime fields where I would save created_hour, created_day, created_month, created_year so I can order them easly.
Do you have some tips?
This is what I mean. You can format the time to be in hours and group by the formatted time.
SELECT DATE_FORMAT(datecolumn, '%H:00'), COUNT(*)
FROM SOURCETABLE
GROUP BY DATE_FORMAT(datecolumn, '%H:00')
I have an array of different times, and I need to order from low to high but directly from the driver, I'm dealing with the following:
var arrayList =[{hora: '8:30'},{hora: '14:30'},{hora:'22:30'},{hora:'07:00'}]
$scope.array =$filter('orderBy')(arrayList, true);
the result is not as expected, that I'm wrong
I'm not proficient with angular, but usually, the problem sorting time variables is that they are stored as strings and not exactly referenced as time variables.
On this cases I usually split them in hours and minutes, multiply hours by 60 and add minutes, then sort for the resulting integer value.