0% found this document useful (0 votes)
16 views3 pages

APCSP Code

The document contains code for a COVID-19 data visualization application. It defines functions for filtering state and date data, getting the weekday for a given date, and handling user interface interactions like button clicks and screen changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

APCSP Code

The document contains code for a COVID-19 data visualization application. It defines functions for filtering state and date data, getting the weekday for a given date, and handling user interface interactions like button clicks and screen changes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

4/3/23, 7:55 PM https://bakerfranke.github.

io/codePrint/

1 //List Variables
2 var date = getColumn("COVID-19 Cases per US State", "Date");
3 var states = getColumn("COVID-19 Cases per US State", "State");
4 var deaths = getColumn("COVID-19 Cases per US State", "Total Deaths");
5 var cases = getColumn("COVID-19 Cases per US State", "Total Confirmed Cases");
6 var weekDays = [""];
7 var filteredDeath = [0];
8 var filteredCases = [0];
9 //Screen Changes
10 onEvent("start", "click", function( ) {
11 setScreen("stateSelection");
12 });
13 onEvent("returnH", "click", function( ) {
14 setScreen("home");
15 });
16 onEvent("datePage", "click", function( ) {
17 setScreen("dateScreen");
18 });
19 onEvent("homeButton2", "click", function( ) {
20 setScreen("home");
21 });
22 onEvent("previousPage", "click", function( ) {
23 setScreen("stateSelection");
24 });
25 onEvent("numDeathButton", "click", function( ) {
26 setScreen("numDeathCases");
27 });
28 onEvent("restartButton", "click", function( ) {
29 setScreen("home");
30 });
31 onEvent("back2", "click", function( ) {
32 setScreen("dateScreen");
33 });
34 //state button
35 onEvent("numDeathButton", "click", function( ) {
36 weekDay(getNumber("monthDropdown"), getNumber("dayDropdown"));
37 filterState(getText("stateDropdown"), weekDays[0]);
38 setText("caseToll", "Total number of Cases is " + filteredCases[0]);
39 setText("deathToll", "Total number of deaths is " + filteredDeath[0]);
40 });
41 //filter
42 //filters the sates and dates so that the correct cases and deaths can be recieved
43 function filterState(state, dates) {
44 removeItem(filteredCases, 0);
45 removeItem(filteredDeath, 0);
46 for (var i = 0; i < states.length; i++) {
47 if (state == states[i] && date[i] == dates) {
48 appendItem(filteredCases, cases[i]);
49 appendItem(filteredDeath, deaths[i]);
50 } else {
51 appendItem(filteredCases, ": No item has been found for that date");
52 appendItem(filteredDeath, ": No item has been found for that date");
53 }

https://bakerfranke.github.io/codePrint/ 1/3
4/3/23, 7:55 PM https://bakerfranke.github.io/codePrint/
54 }
55 }
56 //WeekDay
57 //gets the weekday based on the day selected
58 function weekDay(month, day) {
59 removeItem(weekDays, 0);
60 var o;
61 var weekday = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
62 if (month == 12) {
63 if (day%7==0) {
64 o = 3;
65 } else if ((day%7==1)) {
66 o = 4;
67 } else if ((day%7==2)) {
68 o = 5;
69 } else if ((day%7==3)) {
70 o = 6;
71 } else if ((day%7==4)) {
72 o = 0;
73 } else if ((day%7==5)) {
74 o = 1;
75 } else {
76 o = 2;
77 }
78 } else if ((month == 1)) {
79 if (day%7==0) {
80 o = 6;
81 } else if ((day%7==1)) {
82 o = 0;
83 } else if ((day%7==2)) {
84 o = 1;
85 } else if ((day%7==3)) {
86 o = 2;
87 } else if ((day%7==4)) {
88 o = 3;
89 } else if ((day%7==5)) {
90 o = 4;
91 } else {
92 o = 5;
93 }
94 } else if ((month == 2)) {
95 if (day%7==0) {
96 o = 2;
97 } else if ((day%7==1)) {
98 o = 3;
99 } else if ((day%7==2)) {
100 o = 4;
101 } else if ((day%7==3)) {
102 o = 5;
103 } else if ((day%7==4)) {
104 o = 6;
105 } else if ((day%7==5)) {
106 o = 0;
107 } else {
108 o = 1;
109 }
110
https://bakerfranke.github.io/codePrint/ 2/3
4/3/23, 7:55 PM https://bakerfranke.github.io/codePrint/

111 } else if (month==3) {


112 if (day%7==0) {
113 o = 2;
114 } else if ((day%7==1)) {
115 o = 3;
116 } else if ((day%7==2)) {
117 o = 4;
118 } else if ((day%7==3)) {
119 o = 5;
120 } else if ((day%7==4)) {
121 o = 6;
122 } else if ((day%7==5)) {
123 o = 0;
124 } else {
125 o = 1;
126 }
127 }
128 appendItem(weekDays, weekday[o] + (" " + (month + ("/" + day))));
}

PDF document made with CodePrint using Prism

https://bakerfranke.github.io/codePrint/ 3/3

You might also like