The Most Active and Friendliest
Affiliate Marketing Community Online!

“Propeller”/  Direct Affiliate

Coding success story --YAY! It works!

Graybeard

Well-Known Member
  • Works
Code:
 POPRATIO=$(echo \(9986857/327533795\)|bc -l);\
sed -e 's/^2020/2020\//' -e 's/^2021/2021\//' -e 's#/\([0-9][0-9]\)#/\1/#' USAdaily.csv    \
  |cut -d, -f1,6 | awk -v var="$POPRATIO" -F ',' 'BEGIN{OFS=","} {print $1, $2, $2*var}' \
|sed '1,14!d'  |less
----returns
date,hospitalizedCurrently,0 (really the weighted value[number])
2021/01/19,123820,3775.4
2021/01/18,123848,3776.26
2021/01/17,124387,3792.69
2021/01/16,126139,3846.11
2021/01/15,127235,3879.53
2021/01/14,128947,3931.73
2021/01/13,130391,3975.76
2021/01/12,131326,4004.27
2021/01/11,129793,3957.53
2021/01/10,129223,3940.15
2021/01/09,130781,3987.65
2021/01/08,131921,4022.41
2021/01/07,132370,4036.1

  • WTF is this?

Problem: Create a weighted ratio to compare 2 populations

US state population/ US nation population
ex: 9986857/327533795

now the state
Code:
sed -e 's/^2020/2020\//' -e 's/^2021/2021\//' -e 's#/\([0-9][0-9]\)#/\1/#' ../states/daily.csv  \
    |cut -d, -f1,2,9 |grep MI |awk -F ',' 'BEGIN{OFS=","} {print $1, $2, $3}'\
|sed '1,14!d'  |less

----returns
date,state,hospitalizedCurrently
2021/01/19,MI,2055
2021/01/18,MI,2140
2021/01/17,MI,2222
2021/01/16,MI,2222
2021/01/15,MI,2222
2021/01/14,MI,2238
2021/01/13,MI,2246
2021/01/12,MI,2443
2021/01/11,MI,2396
2021/01/10,MI,2480
2021/01/09,MI,2480
2021/01/08,MI,2480
2021/01/07,MI,2578
2021/01/06,MI,2657
(END)

this took 2 hours grrr and then 15 minutes to fix the error --once I sorted out what it was :rolleyes: --welcome to my nightmare :p

Solution: You have to declare a bash shell variable in awk in order to use it right!
awk -v var="$POPRATIO"
never stop learning :p is the moral of the story. Or, never quit when the problem should have a `logical` answer. (Never beat a dead horse).

  • WTF is this for?

To make a graphical chart that compares the 2 populations hospitalization rate of COVID-19 infections. As you (can|should) see from the numbers the state of MI is lesser than the national population weighted averages.

2021/01/19,MI,2055
2021/01/19,USA,3775.4
2055/3775
or .54437086092715231788 (54.4% of the national population weighted averages)


"California",US,39512223

date,hospitalizedCurrently,0
2021/01/20,122700,14802
2021/01/19,123820,14937.1
2021/01/18,123848,14940.5
2021/01/17,124387,15005.5
2021/01/16,126139,15216.8
2021/01/15,127235,15349.1
2021/01/14,128947,15555.6
2021/01/13,130391,15729.8
2021/01/12,131326,15842.6
2021/01/11,129793,15657.7
2021/01/10,129223,15588.9
2021/01/09,130781,15776.8
2021/01/08,131921,15914.4
(END)




2021/01/19,CA,20942
2021/01/18,CA,20968
2021/01/17,CA,21143
2021/01/16,CA,21579
2021/01/15,CA,21856
2021/01/14,CA,22210
2021/01/13,CA,22550
2021/01/12,CA,22665
2021/01/11,CA,22633
2021/01/10,CA,22513
2021/01/09,CA,22600
2021/01/08,CA,22836
2021/01/07,CA,22851
2021/01/06,CA,22820
(END)
CA California
The state of CA is greater than the national population weighted averages.
20942/14937
1.40202182499832630380
or 140% of the national weighted average 2021/01/19


Sorry no pictures of the charts yet :p

CPA uses? Analysis
scenario:
a large volume CR
compared to your scaled A,B,C ... Tests
---------------------
statistics are statistics and numbers (and their manipulation) are the same ..
 
Last edited:
chart will be in real time updates daily
Liked it at reddit :p
upload_2021-1-21_10-59-32.png
 
PHP is so lame but I need it to do near 4,000 charts dynamically on demand.
upload_2021-1-24_16-22-53.png


USA data is the population proportionate (ratio) of what the death 'should' be --in this case the state Illinois was the 'final test'
IL is the 2char ISO for the US state of Illinois (foreign friends) that is the actual count

it's in arrays x= y=
What a headache-- but the point is: how is your state trending against the national average?
Next are the county subdivisions and metro areas' counties aggregated.

The advertising --affiliate and native are planned.

The program for the world is working --needs to be expanded --but the script prototype is working --PHP w/json, bash to HTML, PHP include. Updated every 189 min?wtf? don't need cron collisions :p
upload_2021-1-24_16-30-50.png

**this is a contest you don't want to be #1 --that's the biggest loser!
I am done for the day. grrr...
 
Last edited:
fixed this with a bash script -- makes 52 files in <2 sec so lame PHP can read them fast;
Code:
0.005905979869955099
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'2423', '2411', '2390', '2367', '2344', '2318', '2305', '2297', '2285', '2263', '2241', '2218', '2194', '2170', '2160', '2147', '2126', '2104', '2080', '2057', '2036'
NE state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04', ''
'1879', '1878', '1868', '1862', '1850', '1842', '1837', '1837', '1837', '1818', '1803', '1791', '1772', '1760', '1737', '1733', '1811', '1703', '1692', '1682', '1672', ''
root@mail:/# php-cgi chart_ratios.php siso=WY

Content-type: text/html; charset=UTF-8

0.0018147654045897767
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'744', '741', '734', '727', '720', '712', '708', '706', '702', '695', '689', '682', '674', '667', '664', '660', '653', '647', '639', '632', '626'
WY state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04', ''
'571', '571', '571', '550', '550', '550', '522', '522', '522', '522', '522', '522', '522', '489', '489', '489', '489', '489', '464', '464', '438', ''
root@mail:/# php-cgi chart_ratios.php siso=WA

Content-type: text/html; charset=UTF-8

0.023249182576717008
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'9537', '9492', '9409', '9316', '9226', '9124', '9074', '9041', '8994', '8907', '8822', '8731', '8636', '8541', '8501', '8453', '8371', '8283', '8188', '8097', '8016'
WA state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04', ''
'4114', '4114', '4065', '3940', '3940', '3903', '3903', '3903', '3903', '3876', '3838', '3789', '3699', '3698', '3698', '3699', '3634', '3605', '3541', '3482', '3459', ''
root@mail:/# php-cgi chart_ratios.php siso=OR

Content-type: text/html; charset=UTF-8

0.01287725744453332
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'5282', '5257', '5211', '5160', '5110', '5053', '5026', '5008', '4981', '4934', '4886', '4836', '4783', '4731', '4709', '4682', '4636', '4588', '4535', '4485', '4440'
OR state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-16', '21-01-15', '21-01-14', '21-01-13', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04', ''
'1877', '1865', '1843', '1832', '1808', '1803', '1800', '1799', '1758', '1737', '1708', '1667', '1613', '1605', '1603', '1575', '1568', '1558', '1550', '1506', '1500', ''
root@mail:/# php-cgi chart_ratios.php siso=OH

Content-type: text/html; charset=UTF-8

0.03568822569896948
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'14640', '14571', '14443', '14301', '14162', '14005', '13929', '13879', '13806', '13673', '13542', '13', '12715', '12569', '12430', '12305'
OH state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04',
'10711', '10680', '10599', '10518', '10409', '10336', '10281', '10200', '10135', '10057', '9990', '9882', '9368', '9247', '9143', ''
root@mail:/# php-cgi chart_ratios.php siso=PA
PHP Notice:  Undefined offset: 2 in //chart_rati
Content-type: text/html; charset=UTF-8

0.03908600942995821
USA data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04'
'16034', '15958', '15818', '15662', '15511', '15338', '15255', '15200', '15120', '14975', '14831', '14', '13925', '13766', '13613', '13477'
PA state's data
'21-01-24', '21-01-23', '21-01-22', '21-01-21', '21-01-20', '21-01-19', '21-01-18', '21-01-17', '21-01-12', '21-01-11', '21-01-10', '21-01-09', '21-01-08', '21-01-07', '21-01-06', '21-01-05', '21-01-04',
'20609', '20526', '20321', '20128', '19868', '19467', '19390', '19310', '19188', '18957', '18742', '18', '17179', '16914', '16546', '16361', ''

but you can see the status > or < the national average ?
will be easier to see it in a line chart --next
 
Well, so far; I can only get one y axis (data points part).
The overlay will not work.
So, now I have to pivot and present the chart differently in just one axis --that makes sense.
canvas1yaxisonly.png

canvas1yaxisonlyAll.png

__had to refresh --the update is on a daily cron______________________________________

So, the math has to be as a % of the national average by state or (county subdivision/state or /national).
e.g.; the state of California death are 98% of the national average and the state of New York is 159% of the national average.

CA= <2% NY=>59% probably is more understandable

=======================

For CPA;
  • If the dates were products and the Y axis prices, then you used a bar style chart --you would have a value analysis in the form of a picture (graph) that is immediately understood with low level reading skills :p
  • For tracking stats --that part should be obvious. You design the metrics for the charts to realize the KPI of each scenario ...
 
Last edited:
  • The scripting was a bitch
  • a double loop and data from 3 files
  • 2 of those files had to be matched and sorted by date.

The script's run time is about 20 seconds and it is updated (cron) every 24 hrs.

Results are displayed as USA (Deaths) as a baseline of 1.0000 proportionate ratio to that states' population

canvas1yaxisonlyAZ-Baseline.png
canvas1yaxisonlyNM-Baseline.png
canvas1yaxisonlyFL-Baseline.png
canvas1yaxisonlyTX-Baseline.png
canvas1yaxisonlyCA-Baseline.png
canvas1yaxisonlyNY-Baseline.png


Is that state better of worse?
Or, is the nation just getting very bad.
There are 430,000 + dead in the USA near 4,000 per day now!
Over 2.2 Million in the world.
 
Last edited:
So why?

upload_2021-2-11_11-0-24.png


I need to chart more data with this but the Pandemic (here in the US) is very confusing and counter-intuitive in many ways (it is seeming).
USA Median =1.000 for the above query
 
it starts to prove some of the most infected areas are rural (or small cities with lower density) by the % of the population
upload_2021-2-15_17-58-27.png


one thing needs to be determined, if this is at all an accurate 'picture' ...
--if the overall % of the population has been tested more or less equally.
 
Haven't updated this in a while;
Without setting up a regressive logarithmic to predict --adding the JavaScript plugin to the chart.js will take too much time :eek:
I came up with a linear approach that seems to be accurate
where: base cases = date=@caseDate2
SET@caseDate2=(SELECT DATE_SUB(curdate() , INTERVAL 63 DAY));
Code:
+------------+
| @caseDate2 |
+------------+
| 2021-01-07 |
upload_2021-3-10_21-5-32.png


TEXAS (in red) /s

upload_2021-3-10_21-7-27.png


by the table you see the death acceleration and accumulation but only linearly

You can see that New York is over the hump (for now anyway)

upload_2021-3-10_21-12-49.png


so the CaseDeath ratio 'looks' right

Question is: Will the better medical treatments developed in the pandemic and the vaccine rollout keep the case rate below the 2% level in the states that are the most recent hot spots?

upload_2021-3-10_21-17-54.png


you can see the jump in a month world wide.
Coding success story --YAY! It works!
 
Last edited:
Actually I expanded it yesterday to more dates
upload_2021-3-12_7-3-3.png


the result
upload_2021-3-12_7-4-8.png


A better trending view
Code:
#!/bin/bash
#-vx
#
#count_add.sh
#
#
################

count=0;
for ((i = 0 ; i < 12; i++)); do
let "count=count+5"; 
echo "SET@caseDate$count=(SELECT DATE_SUB(curdate() , INTERVAL $count DAY));"
done

script to print all the @Set variables ;)
 
MI
Back