# Snow Day Calculator Algorithm

### Start and Finish Time of Storm

To properly predict the chance of a snow day, the calculator must know when the storm starts and ends. This allows it to know the duration of the storm and its offset. For example, a storm that lasts 5 hours and starts at 12 AM would produce a different result than a 5 hour storm starting at 8 PM the night before.

Before we can enter these times into the formula, they must first be put into a format that the formula can understand. To do this, the times are converted to hours since (or to) midnight of the day of the snow day. For example, if the storm started 8 PM the night before, the start time is $$-4$$. If the storm starts at 4 AM the day of, the start time is $$4$$.

Now that our start and finish times of the storm are in an understandable format, we can enter them into the first equation, where $$t_s$$ equals the start time and $$t_f$$ equals the finish time.

$p(t_s,t_f)= (-0.001153t_s^2 - 0.035535t_s + 0.042111) + (0.0428665t_f)$

Note: Explained in later sections, this function alone will accurately return the prediction assuming the chance = 100%, temperature = 0°F, day of week = Monday, school type = public, previous snow days = 0, strength = 1.2, leniency = 0, hype = 3, and not mountainous or special event.

This 2-variable equation is a combination of a polynomic function and a linear function. The polynomic function increases the result as the storm starts earlier, but less over time. The linear function increases the result as the storm finishes later, increasing at a constant rate.

### Strength of Storm

The strength of the storm plays an important factor in how the prediction should be calculated. A storm with higher strength can result in more snow or ice, depending on the storm. This can greatly affect the calculator's result.

On the calculator screen, the dropdown selector has presets with pre-entered values. These are those values:

Type Strength Factor
Snow $$2$$
Light snow / Flurries $$0.7$$
Wintry mix $$1.5$$
Snow showers $$1.2$$
Freezing rain $$2.4$$
Heavy snow $$3$$

The calculator can use these values by generating a linear function based off the strength value. When the formula for the start and finish times of the storm was created, it assumed a strength of $$1.2$$. To accomodate for this, the linear function to create should have a point passing through $$(1.2, p(s,f))$$. The other point to pass through is arbitrary, so a small value, such as $$0.04$$ was chosen. This means if the strength of the storm is $$0$$, the prediction could still be just above 0% (0.04%).

To generate this formula, good ol' slope formula will be used:

$$(\frac{y_2 - y_1}{x_2 - x_1})$$

To fit this with our previous variables, we can adjust the formula, where $$s$$ is the strength:

$$i(t_s,t_f,s) = \frac{p(t_s,t_f) - 0.04}{1.2}s + 0.04$$

### Temperature at 7 AM

The temperature at the time of school starting plays a small factor into the final result. The amount that the final result is affected by is defined by this piecewise function:

$$g(d)=\begin{cases}\frac{7}{12000}d & d < 20\\\frac{1}{1000}d + \frac{11}{347}&20\le d \le 30\\\frac{12}{923}d+\frac{16}{41}&30<d\le34\\\frac{2}{1625}d +\frac{131}{5671}&d >34\end{cases}$$

Simply adding the result of $$g(d)$$ to $$i(t_s,t_f,s)$$ completes this step. We will define this new variable $$x$$.

### Extra Factors

Several small factors can affect the prediction.

##### Day of Week

If the day of the week is a Wednesday, subtract 1% from $$x$$. Else, make no change.

Day Factor
Monday $$\pm 0 \%$$
Tuesday $$\pm 0 \%$$
Wednesday $$- 1 \%$$
Thursday $$\pm 0 \%$$
Friday $$\pm 0 \%$$

##### School Type

To adjust for school type, adjust $$x$$ by the corresponding value in the table below.

School Factor
Public $$\pm 0 \%$$
Urban Public $$- 2 \%$$
Rural Public $$+ 2 \%$$
Private / Preperatory $$+ 2 \%$$
Boarding $$- 5 \%$$

##### Previous Snow Days

To account for previous snow days, the following formula is used, where $$z$$ is the amount of previous snow days:

$$p(z)=0.0085z$$

Simply subtract $$p(z)$$ from $$x$$ to account for previous snow days.

##### Leniency of Administration

To adjust for the leniency of administration, adjust $$x$$ by the corresponding value in the table below.

Leniency Factor
Easy $$+ 5 \%$$
Okay $$\pm 0 \%$$
Harsh $$- 5 \%$$
##### Special Event / Activity & Mountainous Area

If there is a special event / activity the day of the snow day, subtract $$3 \%$$ from $$x$$.

If the school is in a mountainous area, add $$1 \%$$ to $$x$$.

##### Hype Level

To account for hype, the following formula is used, where $$l$$ is the level of hype:

$$h(l)=(-0.01l)+0.03$$

Simply subtract $$h(l)$$ from $$x$$ to account for hype.

And that's it! Now simply multiply $$x$$ by $$100$$ to turn your prediction into a percentage.