Пример #1
0
        public static qHtl_AbsenteeAnalysisVariable GetAbsenteeAnalysisVariablesBySchoolDistrict(int school_district_id)
        {
            qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable();

            variables.container.Select(new DbQuery
            {
                Top     = "Top(1)",
                Where   = string.Format("SchoolDistrictID = " + school_district_id),
                OrderBy = "AbsenteeAnalysisVariableID DESC"
            });

            if (variables.AbsenteeAnalysisVariableID > 0)
            {
                return(variables);
            }
            else
            {
                return(null);
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (school_district_id == 0)
                school_district_id = 1;

            qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(school_district_id);

            string analysis_html = string.Empty;

            analysis_html +=    "<strong>ABSENTEE RATE MULTIPLIERS (x) </strong><br>";
            analysis_html +=    "Green Absentee Rate STD Multiplier = <strong>" + variables.GreenRateSTDMultiplier + "</strong><br>";
            analysis_html +=    "Yellow Absentee Rate STD Multiplier = <strong>" + variables.YellowRateSTDMultiplier + "</strong><br>";
            analysis_html +=    "Red Absentee Rate STD Multiplier = <strong>" + variables.RedRateSTDMultiplier + "</strong><br>";
            analysis_html +=    "<br>";
            analysis_html +=    "<strong>ILLNESS CALCULATIONS (p)</strong><br>";
            analysis_html +=    "Green Status => p < <strong>" + variables.GreenIllnessBoundary + "%</strong> of school's current enrollment<br>";
            analysis_html +=    "Yellow Status => p >= <strong>" + variables.GreenIllnessBoundary + "%</strong> AND p <= <strong>" + variables.RedIllnessBoundary +"%</strong> of school's current enrollment<br>";
            analysis_html +=    "Red Status => p > <strong>" + variables.RedIllnessBoundary + "%</strong> of school's current enrollment<br>";
            analysis_html +=    "<br>";
            analysis_html +=    "<strong>SYMPTOM CALCUATIONS (s)</strong><br>";
            analysis_html +=    "<strong>Gastrointestinal:</strong> Green Status: s < <strong>" + variables.GreenGastrointestinalBoundary + "%</strong>";
            analysis_html +=    " | Yellow Status: <strong>" + variables.GreenGastrointestinalBoundary + "%</strong> <= s <= <strong>" + variables.RedGastrointestinalBoundary + "%</strong>";
            analysis_html +=    " | Red Status: s > <strong>" + variables.RedGastrointestinalBoundary + "%</strong><br>";
            analysis_html +=    "<strong>Respiratory:</strong> Green Status: s < <strong>" + variables.GreenRespiratoryBoundary + "%</strong>";
            analysis_html +=    " | Yellow Status: <strong>" + variables.GreenRespiratoryBoundary + "%</strong> <= s <= <strong>" + variables.RedRespiratoryBoundary + "%</strong>";
            analysis_html +=    " | Red Status: s > <strong>" + variables.RedRespiratoryBoundary + "%</strong><br>";
            analysis_html +=    "<strong>Rash:</strong> Green Status: s < <strong>" + variables.GreenRashBoundary + "%</strong>";
            analysis_html +=    " | Yellow Status: <strong>" + variables.GreenRashBoundary + "%</strong> <= s <= <strong>" + variables.RedRashBoundary + "%</strong>";
            analysis_html +=    " | Red Status: s > <strong>" + variables.RedRashBoundary + "%</strong><br>";
            analysis_html +=    "<strong>Other Illness:</strong> Green Status: s < <strong>" + variables.GreenOtherIllnessBoundary + "%</strong>";
            analysis_html +=    " | Yellow Status: <strong>" + variables.GreenOtherIllnessBoundary + "%</strong> <= s <= <strong>" + variables.RedOtherIllnessBoundary + "%</strong>";
            analysis_html +=    " | Red Status: s > <strong>" + variables.RedOtherIllnessBoundary + "%</strong><br>";
            analysis_html +=    "<strong>Unknown Illness:</strong> Green Status: s < <strong>" + variables.GreenUnknownIllnessBoundary + "%</strong>";
            analysis_html +=    " | Yellow Status: <strong>" + variables.GreenUnknownIllnessBoundary + "%</strong> <= s <= <strong>" + variables.RedUnknownIllnessBoundary + "%</strong>";
            analysis_html +=    " | Red Status: s > <strong>" + variables.RedUnknownIllnessBoundary + "%</strong><br>";

            litAnalysisVariables.Text = analysis_html;
        }
    }
    protected void ProcessAbsenteeData(string[] to_pass)
    {
        int school_district_id = 0;

        if (school_district_id == 0)
            school_district_id = 1;

        qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(school_district_id);

        string mode = to_pass[0];
        string f_name = to_pass[1];
        lblFileName.Text = fileFullName;
        string fileName = string.Format("{0}{1}", Server.MapPath(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Resources_AbsenteeFolder"])), f_name);
        string message = string.Empty;
        string str_solution_start_date = Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["Solution_StartDate"]);

        if (File.Exists(fileName))
        {
            List<string[]> data = parseCSV(fileName);

            message = "RESULTS<br>";
            string eval_date = string.Empty;
            int curr_school_id = 0;
            int curr_school_district_id = 0;
            string curr_school_name = string.Empty;
            string curr_school_level = string.Empty;
            int curr_school_total_absent = 0;
            int curr_school_total_unknown = 0;
            int curr_school_total_other = 0;
            int curr_school_total_sick = 0;
            int curr_school_gastrointestinal = 0;
            int curr_school_respiratory = 0;
            int curr_school_rash = 0;
            int curr_school_other_illness = 0;
            int curr_school_unknown_illness = 0;
            int curr_school_total_enrolled = 0;
            decimal curr_school_rate = 0;
            int num_school_saves = 0;

            bool overall_success = false;
            int total_elementary_schools = 0;
            int total_elementary_students_enrolled = 0;
            int total_elementary_students_absent = 0;
            decimal total_elementary_absentee_rate = 0;
            int total_junior_high_schools = 0;
            int total_junior_high_students_enrolled = 0;
            int total_junior_high_students_absent = 0;
            decimal total_junior_high_absentee_rate = 0;
            int total_high_schools = 0;
            int total_high_school_students_enrolled = 0;
            int total_high_school_students_absent = 0;
            decimal total_high_school_absentee_rate = 0;
            int total_students_enrolled = 0;
            decimal total_absentee_rate = 0;

            int summary_total_absent = 0;
            int summary_total_sick = 0;
            int summary_total_gastrointestinal = 0;
            int summary_total_respiratory = 0;
            int summary_total_rash = 0;
            int summary_total_other_illness = 0;
            int summary_total_unknown_illness = 0;
            int summary_total_enrolled = 0;

            List<double> summary_sch_rates = new List<double>();
            List<double> sch_rates = new List<double>();
            List<double> elem_rates = new List<double>();
            List<double> jr_rates = new List<double>();
            List<double> high_rates = new List<double>();
            List<double> illness_rates = new List<double>();
            List<double> gast_rates = new List<double>();
            List<double> resp_rates = new List<double>();
            List<double> rash_rates = new List<double>();
            List<double> othr_rates = new List<double>();
            List<double> unkn_rates = new List<double>();

            List<ClassroomAbsenteeData> a_data = new List<ClassroomAbsenteeData>();

            string curr_descriptor = string.Empty;
            int prior_school_id = 0;

            string absent_date = string.Empty;
            string school_name = string.Empty;
            string school_type = string.Empty;
            string grade_level = string.Empty;
            string grade_number = string.Empty;
            string class_name = string.Empty;
            string teacher_name = string.Empty;
            int days_in_session = 0;
            int total_enrolled = 0;
            int total_absent = 0;
            int total_unknown = 0;
            int total_other = 0;
            int total_sick = 0;
            int gastrointestinal = 0;
            int respiratory = 0;
            int rash = 0;
            int other_illness = 0;
            int unknown_illness = 0;

            bool success = false;
            string reason = string.Empty;

            int i = 0;
            int s = 0;
            foreach (string[] c in data)
            {
                if (i > 0)
                {
                    absent_date = c[0];
                    school_name = c[1];
                    school_name = school_name.Trim();
                    school_type = c[2];
                    school_type = school_type.Trim();
                    grade_level = c[3];
                    grade_level = grade_level.Trim();
                    class_name = c[4];
                    class_name = class_name.Trim();
                    teacher_name = c[5];
                    teacher_name = teacher_name.Trim();
                    days_in_session = Convert.ToInt32(c[6]);
                    total_enrolled = Convert.ToInt32(c[7]);
                    total_absent = Convert.ToInt32(c[8]);
                    total_unknown = Convert.ToInt32(c[9]);
                    total_other = Convert.ToInt32(c[10]);
                    total_sick = Convert.ToInt32(c[11]);
                    gastrointestinal = Convert.ToInt32(c[12]);
                    respiratory = Convert.ToInt32(c[13]);
                    rash = Convert.ToInt32(c[14]);
                    other_illness = Convert.ToInt32(c[15]);
                    unknown_illness = Convert.ToInt32(c[16]);

                    if (school_type.ToLower().Contains("elem"))
                    {
                        int curr_grade_number = 0;
                        if (grade_level.ToLower().Contains("kinder"))
                            curr_grade_number = 0;
                        else if (grade_level.ToLower().Contains("pre"))
                            curr_grade_number = -1;
                        else
                        {
                            try
                            {
                                curr_grade_number = Convert.ToInt32(grade_level);
                            }
                            catch
                            {
                                curr_grade_number = -2;
                            }
                        }
                        string extra_sort_val = string.Empty;
                        if (curr_grade_number == -1 || curr_grade_number == 0)
                            extra_sort_val = "a";

                        // add to list
                        a_data.Add(new ClassroomAbsenteeData()
                        {
                            sort_by = absent_date + " " + school_name + " " + extra_sort_val + "" + curr_grade_number,
                            absent_date = absent_date,
                            school_name = school_name,
                            school_type = school_type,
                            grade_level = grade_level,
                            grade_number = curr_grade_number,
                            class_name = class_name,
                            teacher_name = teacher_name,
                            days_in_session = days_in_session,
                            total_enrolled = total_enrolled,
                            total_absent = total_absent,
                            total_unknown = total_unknown,
                            total_other = total_other,
                            total_sick = total_sick,
                            gastrointestinal = gastrointestinal,
                            respiratory = respiratory,
                            rash = rash,
                            other_illness = other_illness,
                            unknown_illness = unknown_illness
                        });
                    }
                }

                i++;
            }

            // sort array to insure that it is ordered by school
            a_data.Sort((a, b) => a.sort_by.CompareTo(b.sort_by));

            // clear initial list
            data.Clear();

            int class_count = 0;
            List<double> curr_school_rates = new List<double>();
            List<double> curr_school_all_prior_rates = new List<double>();
            List<double> curr_district_all_prior_rates = new List<double>();

            foreach (var a in a_data)
            {

                class_count ++;

                absent_date = a.absent_date;
                school_name = a.school_name;
                school_type = a.school_type;
                grade_level = a.grade_level;
                grade_number = Convert.ToString(a.grade_number);
                class_name = a.class_name;
                teacher_name = a.teacher_name;
                days_in_session = a.days_in_session;
                total_enrolled = a.total_enrolled;
                total_absent = a.total_absent;
                total_unknown = a.total_unknown;
                total_other = a.total_other;
                total_sick = a.total_sick;
                gastrointestinal = a.gastrointestinal;
                respiratory = a.respiratory;
                rash = a.rash;
                other_illness = a.other_illness;
                unknown_illness = a.unknown_illness;

                curr_descriptor = teacher_name + ", Grade: " + grade_level + " at " + school_name;

                DateTime curr_date = new DateTime();
                curr_date = Convert.ToDateTime(absent_date);

                if (mode == "process")
                {
                    if (String.IsNullOrEmpty(eval_date))
                    {
                        eval_date = absent_date;
                        DateTime curr_eval_date = new DateTime();
                        curr_eval_date = Convert.ToDateTime(eval_date);

                        string final_eval_date = curr_eval_date.ToShortDateString();

                        qHtl_DailyClassroomAbsenteeData.DeleteClassroomAbsenteeDataByDate(final_eval_date);
                        qHtl_DailySchoolAbsenteeData.DeleteSchoolAbsenteeDataByDate(final_eval_date);
                        qHtl_DailySchoolDistrictAbsenteeSummary.DeleteSchoolDistrictAbsenteeSummaryByDate(final_eval_date);
                    }

                    // match the current school and get the school and district_id
                    // first make sure no apostrophes
                    string name_check = school_name.Replace("'", "");
                    var curr_school = qOrg_School.GetSchoolBySelector(name_check);

                    if (curr_school.SchoolID > 0)
                    {
                        // evalute if new school and run appropriate elements
                        curr_school_id = curr_school.SchoolID;
                        if (prior_school_id == 0)
                        {
                            prior_school_id = curr_school_id;
                            curr_school_district_id = curr_school.SchoolDistrictID;
                            curr_school_name = curr_school.School;
                            curr_school_level = curr_school.SchoolLevel;
                        }
                        else if (prior_school_id != curr_school_id || class_count == a_data.Count)
                        {
                            // save values
                            qHtl_DailySchoolAbsenteeData s_data = new qHtl_DailySchoolAbsenteeData();
                            s_data.Created = DateTime.Now;
                            s_data.MarkAsDelete = 0;
                            s_data.SchoolDistrictID = curr_school_district_id;
                            s_data.SchoolID = prior_school_id;
                            s_data.DataDate = Convert.ToDateTime(eval_date).Date;
                            s_data.School = curr_school_name;
                            s_data.SchoolLevel = curr_school_level;
                            s_data.DaysInSession = 1;

                            decimal eval_school_total_absent = Convert.ToDecimal(curr_school_total_absent);
                            decimal eval_school_total_enrolled = Convert.ToDecimal(curr_school_total_enrolled);
                            decimal eval_school_rate = 0;

                            if (num_school_saves > 0)
                            {
                                curr_school_total_absent += total_absent;
                                curr_school_total_unknown += total_unknown;
                                curr_school_total_other += total_other;
                                curr_school_total_sick += total_sick;
                                curr_school_gastrointestinal += gastrointestinal;
                                curr_school_respiratory += respiratory;
                                curr_school_rash += rash;
                                curr_school_other_illness += other_illness;
                                curr_school_unknown_illness += unknown_illness;
                                curr_school_total_enrolled += total_enrolled;
                            }
                            s_data.TotalAbsent = curr_school_total_absent;
                            s_data.TotalUnknown = curr_school_total_unknown;
                            s_data.TotalOther = curr_school_total_other;
                            s_data.TotalSick = curr_school_total_sick;
                            s_data.Gastrointestinal = curr_school_gastrointestinal;
                            s_data.Respiratory = curr_school_respiratory;
                            s_data.Rash = curr_school_rash;
                            s_data.OtherIllness = curr_school_other_illness;
                            s_data.UnknownIllness = curr_school_unknown_illness;
                            s_data.TotalEnrolled = curr_school_total_enrolled;

                            eval_school_rate = Decimal.Divide(curr_school_total_absent, s_data.TotalEnrolled) * 100;
                            s_data.Rate = eval_school_rate;

                            // school rate warning level -- need to get all prior day rates for this school
                            // curr_school_all_prior_rates --> load all prior rates into this list
                            double eval_rate = 0;
                            curr_school_all_prior_rates = qHtl_DailySchoolAbsenteeData.GetAllPriorDailyRatesforSpecificSchool(str_solution_start_date, Convert.ToString(DateTime.Now), prior_school_id, Convert.ToDouble(eval_school_rate));
                            if (variables.SDFormulaType == "population")
                                eval_rate = CalculateSTDPopulationFromList(curr_school_all_prior_rates);      // used to be curr_school_rates when was based on individual classrooms
                            else
                                eval_rate = CalculateSTDFromList(curr_school_all_prior_rates);

                            decimal overal_std = Convert.ToDecimal(eval_rate);
                            s_data.RateSTD = overal_std;

                            // school daily status evaluations
                            int school_illness_absences = (curr_school_gastrointestinal + curr_school_respiratory + curr_school_rash + curr_school_other_illness + curr_school_unknown_illness);

                            decimal school_gast_sym = CalculateSymptomRate(curr_school_gastrointestinal, school_illness_absences);
                            s_data.GastrointestinalRate = school_gast_sym;

                            decimal school_resp_sym = CalculateSymptomRate(curr_school_respiratory, school_illness_absences);
                            s_data.RespiratoryRate = school_resp_sym;

                            decimal school_rash_sym = CalculateSymptomRate(curr_school_rash, school_illness_absences);
                            s_data.RashRate = school_rash_sym;

                            decimal school_othr_sym = CalculateSymptomRate(curr_school_other_illness, school_illness_absences);
                            s_data.OtherRate = school_othr_sym;

                            decimal school_unkn_sym = CalculateSymptomRate(curr_school_unknown_illness, school_illness_absences);
                            s_data.UnknownRate = school_unkn_sym;

                            s_data.Insert();
                            num_school_saves++;

                            summary_sch_rates.Add(Convert.ToDouble(eval_school_rate));

                            // CALCULATE PRIOR SCHOOL RATE AVERAGES - 2 week average rate, prior year average, historic average
                            DateTime solution_start_date = new DateTime();
                            solution_start_date = Convert.ToDateTime(variables.SolutionStartDate);
                            DateTime end_date = new DateTime();
                            end_date = Convert.ToDateTime(s_data.DataDate);
                            DateTime two_weeks_prior = new DateTime();
                            two_weeks_prior = end_date.AddDays(-14);

                            decimal two_week_prior_rate = qHtl_DailySchoolAbsenteeData.CalculateSchoolValuesForRange(Convert.ToString(two_weeks_prior), Convert.ToString(end_date), s_data.Rate, s_data.SchoolID, "rate");
                            decimal historic_rate = qHtl_DailySchoolAbsenteeData.CalculateSchoolValuesForRange(Convert.ToString(solution_start_date), Convert.ToString(end_date), s_data.Rate, s_data.SchoolID, "rate");
                            decimal historic_rate_std = qHtl_DailySchoolAbsenteeData.CalculateSchoolValuesForRange(Convert.ToString(solution_start_date), Convert.ToString(end_date), s_data.RateSTD, s_data.SchoolID, "std");

                            s_data.TwoWeekRate = two_week_prior_rate;
                            s_data.HistoricRate = historic_rate;
                            s_data.HistoricRateSTD = historic_rate_std;
                            s_data.Update();

                            // reset values
                            curr_school_id = curr_school.SchoolID;
                            prior_school_id = curr_school_id;
                            curr_school_district_id = curr_school.SchoolDistrictID;
                            curr_school_name = curr_school.School;
                            curr_school_level = curr_school.SchoolLevel;
                            curr_school_total_absent = 0;
                            curr_school_total_unknown = 0;
                            curr_school_total_other = 0;
                            curr_school_total_sick = 0;
                            curr_school_gastrointestinal = 0;
                            curr_school_respiratory = 0;
                            curr_school_rash = 0;
                            curr_school_other_illness = 0;
                            curr_school_unknown_illness = 0;
                            curr_school_total_enrolled = 0;
                            curr_school_rate = 0;
                            s = 0;
                            curr_school_rates.Clear();

                            if (curr_school.SchoolLevel.ToLower().Contains("elem"))
                            {
                                total_elementary_schools++;
                            }
                            else if (curr_school.SchoolLevel.ToLower().Contains("jr") || curr_school.SchoolLevel.ToLower().Contains("middle"))
                            {
                                total_junior_high_schools++;
                            }
                            else if (curr_school.SchoolLevel.ToLower().Contains("high"))
                            {
                                total_high_schools++;
                            }
                        }

                        // run rate calculation
                        decimal eval_total_absent = Convert.ToDecimal(total_absent);
                        decimal eval_total_enrolled = Convert.ToDecimal(total_enrolled);
                        decimal curr_rate = 0;
                        if (eval_total_enrolled > 0)
                            curr_rate = (eval_total_absent / eval_total_enrolled) * 100;

                        // create daily absentee data
                        qHtl_DailyClassroomAbsenteeData c_data = new qHtl_DailyClassroomAbsenteeData();
                        c_data.Created = DateTime.Now;
                        c_data.MarkAsDelete = 0;
                        c_data.SchoolDistrictID = curr_school.SchoolDistrictID;
                        c_data.SchoolID = curr_school.SchoolID;
                        c_data.DataDate = Convert.ToDateTime(eval_date).Date;
                        c_data.School = curr_school.School;
                        c_data.SchoolLevel = curr_school.SchoolLevel;
                        c_data.GradeLevel = grade_level;
                        c_data.ClassRoom = class_name;
                        c_data.GradeNumber = Convert.ToInt32(grade_number);
                        c_data.Instructor = teacher_name;
                        c_data.DaysInSession = days_in_session;
                        c_data.Rate = curr_rate;
                        c_data.TotalAbsent = total_absent;
                        c_data.TotalUnknown = total_unknown;
                        c_data.TotalOther = total_other;
                        c_data.TotalSick = total_sick;
                        c_data.Gastrointestinal = gastrointestinal;
                        c_data.Respiratory = respiratory;
                        c_data.Rash = rash;
                        c_data.OtherIllness = other_illness;
                        c_data.UnknownIllness = unknown_illness;
                        c_data.TotalEnrolled = total_enrolled;
                        c_data.Insert();

                        // add values to overall school values
                        curr_school_total_absent += total_absent;
                        curr_school_total_unknown += total_unknown;
                        curr_school_total_other += total_other;
                        curr_school_total_sick += total_sick;
                        curr_school_gastrointestinal += gastrointestinal;
                        curr_school_respiratory += respiratory;
                        curr_school_rash += rash;
                        curr_school_other_illness += other_illness;
                        curr_school_unknown_illness += unknown_illness;
                        curr_school_total_enrolled += total_enrolled;
                        curr_school_rate += curr_rate;
                        s++;

                        // add values to daily summary values
                        if (c_data.SchoolLevel.ToLower().Contains("elem"))
                        {
                            total_elementary_students_enrolled += total_enrolled;
                            total_elementary_students_absent += total_absent;
                            total_elementary_absentee_rate += curr_rate;
                            elem_rates.Add(Convert.ToDouble(curr_rate));
                        }
                        else if (c_data.SchoolLevel.ToLower().Contains("jr") || c_data.SchoolLevel.ToLower().Contains("middle"))
                        {
                            total_junior_high_students_enrolled += total_enrolled;
                            total_junior_high_students_absent += total_absent;
                            total_junior_high_absentee_rate += curr_rate;
                            jr_rates.Add(Convert.ToDouble(curr_rate));
                        }
                        else if (c_data.SchoolLevel.ToLower().Contains("high"))
                        {
                            total_high_school_students_enrolled += total_enrolled;
                            total_high_school_students_absent += total_absent;
                            total_high_school_absentee_rate += curr_rate;
                            high_rates.Add(Convert.ToDouble(curr_rate));
                        }
                        total_students_enrolled += total_enrolled;
                        total_absentee_rate += curr_rate;

                        // add to overall list
                        sch_rates.Add(Convert.ToDouble(curr_rate));

                        // add to curr school list
                        curr_school_rates.Add(Convert.ToDouble(curr_rate));

                        // add to other lists
                        illness_rates.Add(Convert.ToDouble(gastrointestinal + respiratory + rash + other_illness + unknown_illness));
                        gast_rates.Add(Convert.ToDouble(gastrointestinal));
                        resp_rates.Add(Convert.ToDouble(respiratory));
                        rash_rates.Add(Convert.ToDouble(rash));
                        othr_rates.Add(Convert.ToDouble(other_illness));
                        unkn_rates.Add(Convert.ToDouble(unknown_illness));

                        // add values to summary list
                        summary_total_absent += total_absent;
                        summary_total_sick += total_sick;
                        summary_total_gastrointestinal += gastrointestinal;
                        summary_total_respiratory += respiratory;
                        summary_total_rash += rash;
                        summary_total_other_illness += other_illness;
                        summary_total_unknown_illness += unknown_illness;
                        summary_total_enrolled += total_enrolled;

                        success = true;
                        overall_success = true;
                    }
                }
                else if (mode == "test")
                {
                    success = true;
                }

                i++;

                if (mode == "process" && success == true)
                {
                    message += "Line " + i + " SUCCESS - " + curr_descriptor + " successfully added to absentee data<br>";
                }
                else if (mode == "test" && success == true)
                {
                    message += "Line " + i + " SUCCESS - " + curr_descriptor + " will be processed<br>";
                }
                else if (i > 1)
                {
                    message += "Line " + i + " FAILURE - could not be added for the following reason: " + reason + "<br>";
                }
                else
                {
                    message += "Line " + i + " LINE NOT PROCESSED - header line in the file<br>";
                }
            }

            // write summary data
            if (overall_success == true)
            {
                qHtl_DailySchoolDistrictAbsenteeSummary d_data = new qHtl_DailySchoolDistrictAbsenteeSummary();
                d_data.Created = DateTime.Now;
                d_data.DataDate = Convert.ToDateTime(eval_date).Date;
                d_data.SchoolDistrictID = curr_school_district_id;

                if (total_elementary_schools > 0)
                {
                    d_data.NumElementarySchools = total_elementary_schools;
                    d_data.TotalElementaryStudents = total_elementary_students_enrolled;
                    d_data.TotalElementaryStudentsAbsent = total_elementary_students_absent;
                    decimal eval_num_elementary_students_enrolled = Convert.ToDecimal(total_elementary_students_enrolled);
                    decimal eval_elem_rate = Convert.ToDecimal(total_elementary_students_absent / eval_num_elementary_students_enrolled) * 100;
                    d_data.ElementarySchoolAbsenteeRate = eval_elem_rate;
                }

                if (total_junior_high_schools > 0)
                {
                    d_data.NumJuniorHighs = total_junior_high_schools;
                    d_data.TotalJuniorHighStudents = total_junior_high_students_enrolled;
                    d_data.TotalJuniorHighStudentsAbsent = total_junior_high_students_absent;
                    decimal eval_num_junior_high_schools = Convert.ToDecimal(total_junior_high_schools);
                    decimal eval_jr_rate = Convert.ToDecimal(total_junior_high_absentee_rate / eval_num_junior_high_schools) * 100;
                    d_data.JuniorHighSchoolAbsenteeRate = eval_jr_rate;
                }

                if (total_high_schools > 0)
                {
                    d_data.NumHighSchools = total_high_schools;
                    d_data.TotalHighSchoolStudents = total_junior_high_students_enrolled;
                    d_data.TotalHighSchoolStudentsAbsent = total_high_school_students_absent;
                    decimal eval_num_high_schools = Convert.ToDecimal(total_high_schools);
                    decimal eval_high_rate = Convert.ToDecimal(total_high_school_absentee_rate / eval_num_high_schools) * 100;
                    d_data.HighSchoolAbsenteeRate = eval_high_rate;
                }

                // overall absentee rate
                decimal eval_total_enrolled = Convert.ToDecimal(total_elementary_students_enrolled + total_high_school_students_enrolled + total_high_school_students_enrolled);
                decimal eval_total_absent = Convert.ToDecimal(total_elementary_students_absent + total_junior_high_absentee_rate + total_high_school_students_absent);
                decimal eval_total_rate = Convert.ToDecimal(eval_total_absent / eval_total_enrolled) * 100;
                d_data.OverallAbsenteeRate = eval_total_rate;

                // calculate warning levels
                double elem_eval_rate = 0;
                if (variables.SDFormulaType == "population")
                    elem_eval_rate = CalculateSTDPopulationFromList(elem_rates);
                else
                    elem_eval_rate = CalculateSTDFromList(elem_rates);
                decimal elem_overal_std = Convert.ToDecimal(elem_eval_rate);
                d_data.ElementarySchoolAbsenteeSTD = elem_overal_std;

                double jr_eval_rate = 0;
                if (variables.SDFormulaType == "population")
                    jr_eval_rate = CalculateSTDPopulationFromList(jr_rates);
                else
                    jr_eval_rate = CalculateSTDFromList(jr_rates);
                decimal jr_overal_std = Convert.ToDecimal(jr_eval_rate);
                d_data.JuniorHighSchoolAbsenteeSTD = jr_overal_std;

                double high_eval_rate = 0;
                if (variables.SDFormulaType == "population")
                    high_eval_rate = CalculateSTDPopulationFromList(high_rates);
                else
                    high_eval_rate = CalculateSTDFromList(high_rates);
                decimal high_overal_std = Convert.ToDecimal(high_eval_rate);
                d_data.HighSchoolAbsenteeSTD = high_overal_std;

                double eval_rate = 0;
                if (variables.SDFormulaType == "population")
                    eval_rate = CalculateSTDPopulationFromList(summary_sch_rates);
                else
                    eval_rate = CalculateSTDFromList(summary_sch_rates);
                decimal overal_std = Convert.ToDecimal(eval_rate);
                d_data.OverallAbsenteeSTD = overal_std;

                // calculate detailed rates -- illness and symptom
                decimal illness_overall_rate = (summary_total_absent / summary_total_enrolled) * 100;
                d_data.IllnessRate = illness_overall_rate;

                int total_illness_absences = (summary_total_gastrointestinal + summary_total_respiratory + summary_total_rash + summary_total_other_illness + summary_total_unknown_illness);

                decimal gast_overall_std = CalculateSymptomRate(summary_total_gastrointestinal, total_illness_absences);
                d_data.GastrointestinalRate = gast_overall_std;

                decimal resp_overall_std = CalculateSymptomRate(summary_total_respiratory, total_illness_absences);
                d_data.RespiratoryRate = resp_overall_std;

                decimal rash_overall_std = CalculateSymptomRate(summary_total_rash, total_illness_absences);
                d_data.RashRate = rash_overall_std;

                decimal othr_overall_std = CalculateSymptomRate(summary_total_other_illness, total_illness_absences);
                d_data.OtherRate = othr_overall_std;

                decimal unkn_overall_std = CalculateSymptomRate(summary_total_unknown_illness, total_illness_absences);
                d_data.UnknownRate = unkn_overall_std;

                d_data.TotalAbsent = summary_total_absent;
                d_data.TotalSick = summary_total_sick;
                d_data.Gastrointestinal = summary_total_gastrointestinal;
                d_data.Respiratory = summary_total_respiratory;
                d_data.Rash = summary_total_rash;
                d_data.OtherIllness = summary_total_other_illness;
                d_data.UnknownIllness = summary_total_unknown_illness;
                d_data.TotalEnrolled = summary_total_enrolled;

                d_data.Insert();

                // CALCULATE PRIOR SCHOOL RATE AVERAGES - 2 week average rate, prior year average, historic average
                DateTime solution_start_date = new DateTime();
                solution_start_date = Convert.ToDateTime(variables.SolutionStartDate);
                DateTime end_date = new DateTime();
                end_date = Convert.ToDateTime(d_data.DataDate);
                DateTime two_weeks_prior = new DateTime();
                two_weeks_prior = end_date.AddDays(-14);

                // historic rate
                decimal two_week_prior_rate = qHtl_DailySchoolDistrictAbsenteeSummary.CalculateAbsenteeRateForRange(Convert.ToString(two_weeks_prior), Convert.ToString(end_date), d_data.OverallAbsenteeRate);
                decimal historic_rate = qHtl_DailySchoolDistrictAbsenteeSummary.CalculateAbsenteeRateForRange(Convert.ToString(solution_start_date), Convert.ToString(end_date), d_data.OverallAbsenteeRate);
                d_data.TwoWeekAbsenteeRate = two_week_prior_rate;
                d_data.HistoricAbsenteeRate = historic_rate;

                // historic std
                decimal historic_std = qHtl_DailySchoolDistrictAbsenteeSummary.CalculateAbsenteeRateSTDForRange(Convert.ToString(solution_start_date), Convert.ToString(end_date), d_data.OverallAbsenteeSTD);
                d_data.HistoricAbsenteeSTD = historic_std;

                // district prior rate stds
                double eval_historic_district_std = 0;
                curr_district_all_prior_rates = qHtl_DailySchoolDistrictAbsenteeSummary.GetAllPriorDailyRatesforDistrict(str_solution_start_date, Convert.ToString(DateTime.Now), 0);
                if (variables.SDFormulaType == "population")
                    eval_historic_district_std = CalculateSTDPopulationFromList(curr_district_all_prior_rates);      // used to be curr_school_rates when was based on individual classrooms
                else
                    eval_historic_district_std = CalculateSTDFromList(curr_district_all_prior_rates);

                decimal overall_district_std = Convert.ToDecimal(eval_historic_district_std);
                d_data.HistoricDistrictAbsenteeSTD = overall_district_std;

                // run analysis for this date
                DateTime curr_date = DateTime.Now;
                curr_date = Convert.ToDateTime(eval_date);

                int num_schools = qHtl_DailySchoolAbsenteeData.AnalyzeDailySchoolDataByDate(curr_date, school_district_id);

                // run code to count number of daily warnings
                int num_a_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("A", curr_date);
                int num_b_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("B", curr_date);
                int num_c_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("C", curr_date);
                int num_d_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("D", curr_date);
                int num_e_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("E", curr_date);
                int num_f_warn = qHtl_DailySchoolAbsenteeData.GetNumWarningsByTypeAndDay("F", curr_date);

                d_data.NumAWarnings = num_a_warn;
                d_data.NumBWarnings = num_b_warn;
                d_data.NumCWarnings = num_c_warn;
                d_data.NumDWarnings = num_d_warn;
                d_data.NumEWarnings = num_e_warn;
                d_data.NumFWarnings = num_f_warn;
                d_data.Update();
            }

            if (mode == "process")
            {
                lblMessage.Text = message;
                plhStep3.Visible = false;
                plhStep3Completed.Visible = true;
            }
            else if (mode == "test")
            {
                lblTestOutput.Text = message;
                plhStep3.Visible = true;
                plhStep2Completed.Visible = true;
                lblUploadFail.Text = "";
            }
        }
    }
        public static int AnalyzeDailySchoolDataByDate(DateTime curr_date, int school_district_id)
        {
            int schools_analyzed = 0;

            var schools = qHtl_DailySchoolAbsenteeData.GetDailySchoolAbsenteeDataCollectionByDate(curr_date);

            if (schools != null)
            {
                if (schools.Count > 0)
                {
                    qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(school_district_id);

                    foreach (var s in schools)
                    {
                        // delete any warnings for this school on this date
                        qHtl_HealthWarning.DeleteWarningsBySchoolAndDate(s.SchoolID, Convert.ToString(s.DataDate));

                        var summary = new qHtl_DailySchoolDistrictAbsenteeSummary();

                        if (summary != null)
                        {
                            if (summary.DataDate != s.DataDate)
                                summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryByDate(Convert.ToString(s.DataDate));
                        }
                        else
                        {
                            summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryByDate(Convert.ToString(s.DataDate));
                        }

                        bool a_warning_status = false;
                        string a_warning_evals = string.Empty;
                        bool b_warning_status = false;
                        string b_warning_evals = string.Empty;
                        bool c_warning_status = false;
                        string c_warning_evals = string.Empty;
                        bool d_warning_status = false;
                        string d_warning_evals = string.Empty;
                        bool e_warning_status = false;
                        string e_warning_evals = string.Empty;
                        bool f_warning_status = false;
                        string f_warning_evals = string.Empty;
                        string absentee_status = "green";
                        string absentee_status_7day = "green";
                        string absentee_status_school = "green";
                        string absentee_status_school_7day = "green";
                        string illness_status = "green";
                        string gast_status = "green";
                        string resp_status = "green";
                        string rash_status = "green";
                        string othr_status = "green";
                        string unkn_status = "green";
                        string warning_type = "School Daily Absentee Status Warning";
                        string warning_status = string.Empty;
                        string warning_title = string.Empty;
                        string warning_text = string.Empty;

                        int num_warnings = 0;

                        // perform A-E warning analysis
                        DateTime anal_date = new DateTime();
                        anal_date = Convert.ToDateTime(s.DataDate);
                        var data_days = GetDailySchoolAbsenteeDataCollectionByDateRangeAndSchool(8, anal_date.AddDays(1), s.SchoolID);
                        int x = 0;
                        bool run_check = true;
                        decimal curr_rate = 0;
                        decimal prior_rate = 0;

                        // check A -- One point/day above 3 sigma
                        decimal historic_avg = 0;
                        decimal curr_std = 0;
                        decimal a_eval = 0;
                        foreach (var d in data_days)
                        {
                            x++;
                            if (x == 1)
                            {
                                curr_rate = d.Rate;
                                curr_std = d.RateSTD;
                                historic_avg = d.HistoricRate;
                            }
                        }
                        if (curr_std > 0)
                        {
                            a_eval = historic_avg + (3 * curr_std);
                            a_warning_evals = Convert.ToString(Math.Round(a_eval, 2));
                            if (curr_rate > a_eval)
                                a_warning_status = true;
                        }

                        // check F -- 1 day above 2 sigma
                        decimal f_eval = 0;
                        foreach (var d in data_days)
                        {
                            x++;
                            if (x == 1)
                            {
                                curr_rate = d.Rate;
                                curr_std = d.RateSTD;
                                historic_avg = d.HistoricRate;
                            }
                        }
                        if (curr_std > 0)
                        {
                            f_eval = historic_avg + (2 * curr_std);
                            f_warning_evals = Convert.ToString(Math.Round(f_eval, 2));
                            if (curr_rate > f_eval)
                                f_warning_status = true;
                        }

                        // check B -- 2 out of 3 days above 2 standard deviations
                        x = 0;
                        curr_std = 0;
                        curr_rate = 0;
                        historic_avg = 0;
                        decimal b_value = 0;
                        int b_meets = 0;
                        foreach (var d in data_days)
                        {
                            if (x < 3)
                            {
                                curr_rate = d.Rate;
                                curr_std = d.RateSTD;
                                historic_avg = d.HistoricRate;

                                if (x == 0 || x == 1 || x == 2)
                                {
                                    b_value = historic_avg + (2 * curr_std);
                                    b_warning_evals += " " + Convert.ToString(Math.Round(b_value, 2));
                                    if (curr_rate > b_value)
                                        b_meets++;
                                }
                            }
                            x++;
                        }
                        if (b_meets >= 2)
                            b_warning_status = true;

                        // check C -- 4 out of 5 days above 1 standard deviations
                        x = 0;
                        curr_std = 0;
                        curr_rate = 0;
                        historic_avg = 0;
                        decimal c_value = 0;
                        int c_meets = 0;
                        foreach (var d in data_days)
                        {
                            if (x < 5)
                            {
                                curr_rate = d.Rate;
                                curr_std = d.RateSTD;
                                historic_avg = d.HistoricRate;

                                if (x == 0 || x == 1 || x == 2 || x == 3 || x == 4)
                                {
                                    c_value = historic_avg + (1 * curr_std);
                                    c_warning_evals += " " + Convert.ToString(Math.Round(c_value, 2));
                                    if (curr_rate > c_value)
                                        c_meets++;
                                }
                            }
                            x++;
                        }
                        if (c_meets >= 4)
                            c_warning_status = true;

                        // check D -- 8 consecutive days above the moving average
                        x = 0;
                        int d_check_threshold = 8;
                        run_check = true;
                        int d_num_days = 0;
                        decimal moving = 0;
                        prior_rate = 0;
                        foreach (var d in data_days)
                        {
                            if (x == 0)
                                moving = d.HistoricRate;

                            if (x < d_check_threshold)
                            {
                                curr_rate = d.Rate;
                                if (run_check == true)
                                {
                                    if (curr_rate > moving)
                                    {
                                        run_check = true;
                                        d_num_days++;
                                    }
                                    else
                                        run_check = false;
                                }
                                prior_rate = curr_rate;
                                d_warning_evals += " " + Convert.ToString(Math.Round(curr_rate, 2));
                                x++;
                            }
                        }
                        if (d_num_days == d_check_threshold)
                            d_warning_status = true;

                        // check E -- 6 days of increasing absentee rates
                        x = 0;
                        int e_check_threshold = 6;
                        run_check = true;
                        int e_num_days = 0;
                        curr_rate = 0;
                        prior_rate = 0;
                        foreach (var d in data_days)
                        {
                            if (x < e_check_threshold)
                            {
                                curr_rate = d.Rate;
                                if (run_check == true)
                                {
                                    if (curr_rate < prior_rate)
                                    {
                                        run_check = true;
                                        e_num_days++;
                                    }
                                    else
                                        run_check = false;
                                }
                                prior_rate = curr_rate;
                                e_warning_evals += " " + Convert.ToString(Math.Round(curr_rate, 2));
                                x++;
                            }
                        }
                        if (e_num_days == e_check_threshold)
                            e_warning_status = true;

                        // perform analysis
                        if (s.Rate < (summary.OverallAbsenteeSTD * variables.GreenRateSTDMultiplier))
                            absentee_status = "green";
                        else if (s.Rate >= (summary.OverallAbsenteeSTD * variables.YellowRateSTDMultiplier))
                        {
                            absentee_status = "yellow";
                            warning_status += "yellow ";
                            warning_status += "red ";
                            warning_title = "Yellow Status | Absentee Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Absentee Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Absentee rate of " + Math.Round(s.Rate, 2) + "% is greater than " + (summary.OverallAbsenteeSTD * variables.YellowRateSTDMultiplier) + "% or less than " + (summary.OverallAbsenteeSTD * variables.RedRateSTDMultiplier) + "% of the school's enrollment.<br><br>";
                            num_warnings++;
                        }
                        else if (s.Rate >= (s.RateSTD * variables.RedRateSTDMultiplier))
                        {
                            absentee_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Absentee Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Absentee Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Absentee rate of " + Math.Round(s.Rate, 2) + "% is greater than " + (summary.OverallAbsenteeSTD * variables.RedRateSTDMultiplier) + " of the school's enrollment.<br><br>";
                            num_warnings++;
                        }

                        if (s.IllnessRate < variables.GreenIllnessBoundary)
                            illness_status = "green";
                        else if (s.IllnessRate >= variables.GreenIllnessBoundary && s.IllnessRate <= variables.RedIllnessBoundary)
                        {
                            illness_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Illness rate of " + Math.Round(s.IllnessRate, 2) + "% is between " + variables.GreenIllnessBoundary + " and " + variables.RedIllnessBoundary + " of the school's enrollment.<br><br>";
                            num_warnings++;
                        }
                        else if (s.IllnessRate > variables.RedIllnessBoundary)
                        {
                            illness_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Illness rate of " + Math.Round(s.IllnessRate, 2) + "% is greater than " + variables.RedIllnessBoundary + " of the school's enrollment.<br><br>";
                            num_warnings++;
                        }

                        if (s.GastrointestinalRate < variables.GreenGastrointestinalBoundary)
                            gast_status = "green";
                        else if (s.GastrointestinalRate >= variables.GreenGastrointestinalBoundary && s.GastrointestinalRate <= variables.RedGastrointestinalBoundary)
                        {
                            gast_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Gastrintestinal Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Gastrintestinal Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Gastrintestinal symptom rate of " + Math.Round(s.GastrointestinalRate, 2) + "% is between " + variables.GreenGastrointestinalBoundary + " and " + variables.RedGastrointestinalBoundary + " of all school absences with reported symptoms.<br><br>";
                            num_warnings++;
                        }
                        else if (s.GastrointestinalRate > variables.RedGastrointestinalBoundary)
                        {
                            gast_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Gastrintestinal Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Gastrintestinal Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Gastrintestinal symptom rate of " + Math.Round(s.GastrointestinalRate, 2) + "% is greater than " + variables.RedGastrointestinalBoundary + " of all school absences with reported symptoms.<br><br>"; ;
                            num_warnings++;
                        }

                        if (s.RespiratoryRate < variables.GreenRespiratoryBoundary)
                            resp_status = "green";
                        else if (s.RespiratoryRate >= variables.GreenRespiratoryBoundary && s.RespiratoryRate <= variables.RedRespiratoryBoundary)
                        {
                            resp_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Respiratory Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Respiratory Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Respiratory symptom rate of " + Math.Round(s.RespiratoryRate, 2) + "% is between " + variables.GreenRespiratoryBoundary + " and " + variables.RedRespiratoryBoundary + " of all school absences with reported symptoms.<br><br>";
                            num_warnings++;
                        }
                        else if (s.RespiratoryRate > variables.RedRespiratoryBoundary)
                        {
                            resp_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Respiratory Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Respiratory Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Respiratory symptom rate of " + Math.Round(s.RespiratoryRate, 2) + "% is greater than " + variables.RedRespiratoryBoundary + "% of all school absences with reported symptoms.<br><br>"; ;
                            num_warnings++;
                        }

                        if (s.RashRate < variables.GreenRashBoundary)
                            rash_status = "green";
                        else if (s.RashRate >= variables.GreenRashBoundary && s.RespiratoryRate <= variables.RedRashBoundary)
                        {
                            rash_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Rash Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Rash Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Rash symptom rate of " +Math.Round(s.RashRate, 2) + "% is between " + variables.GreenRashBoundary + "% and " + variables.RedRashBoundary + "% of all school absences with reported symptoms.<br><br>";
                            num_warnings++;
                        }
                        else if (s.RashRate > variables.RedRashBoundary)
                        {
                            rash_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Rash Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Rash Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Rash symptom rate of " + Math.Round(s.RashRate, 2) + "% is greater than " + variables.RedRashBoundary + "% of all school absences with reported symptoms.<br><br>"; ;
                            num_warnings++;
                        }

                        if (s.OtherRate < variables.GreenOtherIllnessBoundary)
                            othr_status = "green";
                        else if (s.OtherRate >= variables.GreenOtherIllnessBoundary && s.RespiratoryRate <= variables.RedOtherIllnessBoundary)
                        {
                            othr_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Other Illness Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Other Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Other illness symptom rate of " + Math.Round(s.OtherRate, 2) + "% is between " + variables.GreenOtherIllnessBoundary + "% and " + variables.RedOtherIllnessBoundary + "% of all school absences with reported symptoms.<br><br>";
                            num_warnings++;
                        }
                        else if (s.OtherRate > variables.RedOtherIllnessBoundary)
                        {
                            othr_status = "red";
                            warning_status += "yellow ";
                            warning_title = "Red Status | Other Illness Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Other Illness Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Other illness symptom rate of " + Math.Round(s.OtherRate, 2) + "% is greater than " + variables.RedOtherIllnessBoundary + "% of all school absences with reported symptoms.<br><br>"; ;
                            num_warnings++;
                        }

                        if (s.UnknownRate < variables.GreenUnknownIllnessBoundary)
                            unkn_status = "green";
                        else if (s.UnknownRate >= variables.GreenUnknownIllnessBoundary && s.RespiratoryRate <= variables.RedUnknownIllnessBoundary)
                        {
                            unkn_status = "yellow";
                            warning_status += "yellow ";
                            warning_title = "Yellow Status | Unknown Illness Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Yellow Status</strong> | Unknown Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Unknown illness symptom rate of " + Math.Round(s.UnknownRate, 2) + "% is between " + variables.GreenUnknownIllnessBoundary + "% and " + variables.RedUnknownIllnessBoundary + "% of all school absences with reported symptoms.<br><br>";
                            num_warnings++;
                        }
                        else if (s.UnknownRate > variables.RedUnknownIllnessBoundary)
                        {
                            unkn_status = "red";
                            warning_status += "red ";
                            warning_title = "Red Status | Unknown Illness Symptom Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<strong>Red Status</strong> | Unknown Illness Rate at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);
                            warning_text += "<br><strong>Reason</strong>: Unknown illness symptom rate of " + Math.Round(s.OtherRate, 2) + "% is greater than " + variables.RedUnknownIllnessBoundary + "% of all school absences with reported symptoms.<br><br>"; ;
                            num_warnings++;
                        }

                        // update record
                        qHtl_DailySchoolAbsenteeData curr_school = new qHtl_DailySchoolAbsenteeData(s.SchoolID, curr_date);
                        curr_school.AbsenteeStatus = absentee_status;
                        curr_school.AbsenteeStatus7Day = absentee_status_7day;
                        curr_school.AbsenteeStatusSchool = absentee_status_school;
                        curr_school.AbsenteeStatusSchool7Day = absentee_status_school_7day;
                        curr_school.IllnessStatus = illness_status;
                        curr_school.GastrointestinalStatus = gast_status;
                        curr_school.RespiratoryStatus = resp_status;
                        curr_school.RashStatus = rash_status;
                        curr_school.OtherIllnessStatus = othr_status;
                        curr_school.UnknownIllnessStatus = unkn_status;
                        curr_school.A_Warning = a_warning_status;
                        curr_school.A_WarningValues = a_warning_evals;
                        curr_school.B_Warning = b_warning_status;
                        curr_school.B_WarningValues = b_warning_evals;
                        curr_school.C_Warning = c_warning_status;
                        curr_school.C_WarningValues = c_warning_evals;
                        curr_school.D_Warning = d_warning_status;
                        curr_school.D_WarningValues = d_warning_evals;
                        curr_school.E_Warning = e_warning_status;
                        curr_school.E_WarningValues = e_warning_evals;
                        curr_school.F_Warning = f_warning_status;
                        curr_school.F_WarningValues = f_warning_evals;
                        curr_school.Update();

                        if (num_warnings > 1)
                            warning_title = "Multiple School Absentee Status Warnings at " + s.School + " (" + s.SchoolLevel + " School) on " + String.Format("{0:MMMM d, yyyy}", s.DataDate);

                        if (num_warnings > 0)
                            CreateSchoolWarning(s.SchoolID, Convert.ToDateTime(s.DataDate), warning_status, warning_type, warning_title, warning_text);
                    }

                    schools_analyzed = schools.Count;
                }
            }

            return schools_analyzed;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        int curr_school_district_id = 0;
        if (school_district_id == 0)
            school_district_id = 1;

        qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(school_district_id);

        if (!Page.IsPostBack)
        {
            var summary = new qHtl_DailySchoolDistrictAbsenteeSummary();

            if (String.IsNullOrEmpty(Request.QueryString["currDate"]))
            {
                summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetMostRecentDailySummary();
            }
            else
            {
                string eval_curr_date = Convert.ToString(Request.QueryString["currDate"]);
                summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryByDate(eval_curr_date);
            }

            if (summary != null)
            {
                if (summary.DailySchoolDistrictAbsenteeSummaryID > 0)
                {
                    DateTime curr_date = new DateTime();
                    curr_date = Convert.ToDateTime(summary.DataDate);
                    DailySchoolAbsenteeDashboard.CurrDate = curr_date;

                    Session["curr_date"] = curr_date;

                    litDataDate.Text = String.Format("{0:dddd, MMMM d, yyyy}", curr_date);

                    // possibly add daily school level details control
                }

                schooldistrictsidebar.Summary = summary;
                //DailySummaryCharts.Summary = summary;

                var prior_summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryPriorOrAfter("prior", Convert.ToString(summary.DataDate));
                var after_summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryPriorOrAfter("after", Convert.ToString(summary.DataDate));

                if (prior_summary != null)
                {
                    if (prior_summary.DailySchoolDistrictAbsenteeSummaryID > 0)
                    {
                        string prior_date = String.Format("{0:M/d/yyyy}", prior_summary.DataDate);
                        litDateBefore.Text = "<a href=\"default.aspx?currDate=" + prior_date + "\" class=\"btn btn-large\"><i class=\"glyphicon-step_backward\"></i></a>";
                    }
                }
                if (after_summary != null)
                {
                    if (after_summary.DailySchoolDistrictAbsenteeSummaryID > 0)
                    {
                        string after_date = String.Format("{0:M/d/yyyy}", after_summary.DataDate);
                        litDateAfter.Text = "<a href=\"default.aspx?currDate=" + after_date + "\" class=\"btn btn-large\"><i class=\"glyphicon-step_forward\"></i></a>";
                    }
                }
            }
        }

        if (!String.IsNullOrEmpty(Request.QueryString["schoolDistrictID"]))
        {
            curr_school_district_id = Convert.ToInt32(Request.QueryString["spaceID"]);
        }
        else
        {
            // get first space associated with this user
            var districts = qPtl_SchoolDistrictAdmin_View.GetSchoolDistrictAdminsByUser(Convert.ToInt32(Context.Items["UserID"]));
            int i = 0;
            foreach (var d in districts)
            {
                if (i == 0)
                {
                    curr_school_district_id = d.SchoolDistrictID;

                    // set session variable

                }
                i++;
            }
        }
        school_district_id = curr_school_district_id;
        loadPageInfo(curr_school_district_id);
        schooldistrictsidebar.SchoolDistrictID = curr_school_district_id;
    }
        public static qHtl_AbsenteeAnalysisVariable GetAbsenteeAnalysisVariablesBySchoolDistrict(int school_district_id)
        {
            qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable();

            variables.container.Select(new DbQuery
            {
                Top = "Top(1)",
                Where = string.Format("SchoolDistrictID = " + school_district_id),
                OrderBy = "AbsenteeAnalysisVariableID DESC"
            });

            if (variables.AbsenteeAnalysisVariableID > 0) return variables;
            else return null;
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            int school_id = 0;

            if (!String.IsNullOrEmpty(Request.QueryString["schoolID"]))
                school_id = Convert.ToInt32(Request.QueryString["schoolID"]);

            // get school daily summary
            var daily_summary = qHtl_DailySchoolAbsenteeData.GetSchoolDailySummaryByDate(school_id, Convert.ToString(curr_date));

            // school
            qOrg_School school = new qOrg_School(school_id);
            litSchoolTitle.Text = school.School;
            string address = string.Empty;
            address = school.Address1;
            if (!String.IsNullOrEmpty(school.Address2))
                address += "<br>" + school.Address2;
            address += "<br>" + school.City;
            address += ", " + school.StateProvince;
            address += " " + school.PostalCode;
            litSchoolAddress.Text = address;
            litSchoolPhone.Text = school.SchoolPhone;
            litSchoolFax.Text = school.SchoolFax;
            litSchoolLevel.Text = school.SchoolLevel;
            litDistrict.Text = school.District;

            // get classroom data
            List<ClassroomData> data = new List<ClassroomData>();
            data = qHtl_DailyClassroomAbsenteeData.LoadDailyClassroomDataInfoList(curr_date, school_id);

            // get past data
            string curr_mode = string.Empty;
            string mode_x_axis = "4 Weeks";
            if (!String.IsNullOrEmpty(Request.QueryString["mode"]))
            {
                curr_mode = Request.QueryString["mode"];
                if (curr_mode == "28_day")
                {
                    lit28DayTitle.Text = "4 Weeks of " + school.School + " Absentee Data";
                    mode_x_axis = "4 Weeks";
                }
                else if (curr_mode == "this_year")
                {
                    lit28DayTitle.Text = "Current School Year " + school.School + " Absentee Data";
                    mode_x_axis = "Current School Year";
                }
                else
                {
                    lit28DayTitle.Text = "4 Weeks of " + school.School + " Absentee Data";
                    mode_x_axis = "4 Weeks";
                }
            }
            else
                lit28DayTitle.Text = "4 Weeks of " + school.School + " Absentee Data";

            // build options
            string filter_options = string.Empty;
            string qs_options = string.Empty;
            if (!String.IsNullOrEmpty(Request.QueryString["currDate"]))
                qs_options = "currDate=" + Request.QueryString["currDate"];

            filter_options += "<li><a href=\"/manage/school-districts/default.aspx?" + qs_options + "&mode=28_day\">Last 28 Days</a></li>";
            filter_options += "<li><a href=\"/manage/school-districts/default.aspx?" + qs_options + "&mode=this_year\">This School Year</a></li>";
            litFilterByDateOptions.Text = filter_options;

            // get 28 days of district data
            List<SchoolData> d_data = new List<SchoolData>();
            d_data = qHtl_DailySchoolAbsenteeData.LoadDayDailySchoolDataInfoListByMode(curr_mode, curr_date, school_id);

            litDailyDashboardTitle.Text = school.School + " Absentee Data for " + String.Format("{0:dddd, MMMM d, yyyy}", curr_date);
            litCalendarDate.Text = String.Format("{0:dddd, MMMM d, yyyy}", curr_date);
            litStatusCurrentDay.Text = String.Format("{0:dddd, MMMM d, yyyy}", curr_date);
            litTotalEnrolled.Text = String.Format("{0:0,0}", daily_summary.TotalEnrolled);
            litTotalStudents.Text = String.Format("{0:0,0}", daily_summary.TotalEnrolled);
            litTotalAbsent.Text = String.Format("{0:0,0}", daily_summary.TotalAbsent);
            litTotalSick.Text = String.Format("{0:0,0}", daily_summary.TotalSick);
            litAbsenteeRate.Text = Convert.ToString(Math.Round(daily_summary.Rate, 2));
            litHistoricAbsenteeRate.Text = Convert.ToString(Math.Round(daily_summary.HistoricRate, 2));

            // ******************* google map -- school status *******************
            string strJSMap = string.Empty;
            strJSMap += "<script>\n";
            strJSMap += "function initialize() {\n";
            strJSMap += "var myLatlng = new google.maps.LatLng(" + school.Latitude + ", " + school.Longitude + ");\n";
            strJSMap += "var mapOptions = {\n";
            strJSMap += "zoom: 10,\n";
            strJSMap += "scrollwheel: false,\n";
            strJSMap += "center: myLatlng\n";
            strJSMap += "}\n";
            strJSMap += "var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);\n\n";
            strJSMap += "var marker = new google.maps.Marker({position: myLatlng, map: map, title: '" + school.School + "'});};\n\n";
            strJSMap += "google.maps.event.addDomListener(window, 'load', initialize);\n";
            strJSMap += "</script>\n\n";

            litMap.Text = strJSMap;
            // *********************************************************************

            if (data != null)
            {
                // create opening/closing for chart javascript
                string strJSLoad = string.Empty;

                string strJSOpening = string.Empty;
                strJSOpening += "<script type=\"text/javascript\">\n";
                litJSOpening.Text = strJSOpening;

                string strJSClosing = string.Empty;
                strJSClosing += "</script>\n";
                litJSClosing.Text = strJSClosing;

                string strJSChart = string.Empty;

                // ******************* google chart bar -- school list *******************
                string school_chart_title = "Classroom Absentee Rates " + String.Format("{0:M/d/yyyy}", curr_date);

                strJSChart += "function drawAbsences() {\n";
                strJSChart += "var dataAbsentee = google.visualization.arrayToDataTable([\n";

                strJSChart += "['Classroom', 'Classroom Daily Absentee Rate', { role: 'style' }, 'School Daily Absentee Rate', 'School Moving Average Absentee Rate'],\n";
                int j = 0;
                foreach (var s in data)
                {
                    if (j < data.Count && j > 0)
                        strJSChart += ",\n";
                    strJSChart += "['" + s.chart_classroom_name + "', " + Math.Round(s.rate, 2) + ", '" + s.classroom_color + "', " + Math.Round(daily_summary.Rate, 2) + ", " + Math.Round(daily_summary.HistoricRate, 2) + "]";
                    j++;
                }
                strJSChart += "]);\n";

                strJSChart += "var options = {\n";
                strJSChart += "title: '" + school_chart_title + "',\n";
                strJSChart += "hAxis: {tile: \"Schools\", slantedText: true},\n";
                strJSChart += "vAxis: {title: 'Absentee Rate (%)'},\n";
                strJSChart += "seriesType: \"bars\",\n";
                strJSChart += "series: {1: {color: 'gray', type: \"line\"}, 2: {color: 'blue', type: \"line\"}}\n";
                strJSChart += "};\n\n";

                strJSChart += "var chart = new google.visualization.ComboChart(document.getElementById('visualizationSchoolAbsences'))\n";
                strJSChart += "chart.draw(dataAbsentee, options);\n\n";
                strJSChart += "}\n";

                strJSLoad += "drawAbsences();\n";

                strJSChart += "var selectHandler = function(e) {\n";
                strJSChart += "alert('just clicked on this item')\n";
                strJSChart += "window.location = data.getValue(chart.getSelection()[0]['row'], 1 );\n";
                strJSChart += "}\n";
                strJSChart += "google.visualization.events.addListener(chart, 'select', selectHandler);\n";

                litClassrooms.Text = "<div id=\"visualizationSchoolAbsences\" style=\"height: 600px;\"></div>";
                // *********************************************************************

                // ******************* google chart pie -- illnesses *******************
                int total_illness = daily_summary.Gastrointestinal + daily_summary.Rash + daily_summary.Respiratory + daily_summary.Rash + daily_summary.OtherIllness;
                int total_unknown = daily_summary.TotalAbsent - total_illness;

                strJSChart += "function drawIllnesses() {\n";
                strJSChart += "var data = google.visualization.arrayToDataTable([\n";
                strJSChart += "['Reason', 'Nuumber of Absences'],\n";
                strJSChart += "['Illness', " + total_illness + "],\n";
                strJSChart += "['Unknown', " + total_unknown + "]\n";
                strJSChart += "]);\n";
                strJSChart += "new google.visualization.PieChart(document.getElementById('visualizationIllness')).draw(data, {title:\"Types of Absences\"});\n";
                strJSChart += "}\n";

                strJSLoad += "drawIllnesses();\n";
                litTypesOfIllnessesChartGoogle.Text = "<div id=\"visualizationIllness\" style=\"width: 600px; height: 400px;\"></div>";
                // *********************************************************************

                // ******************* google chart bar -- symptoms *******************
                strJSChart += "function drawSymptoms() {\n";
                strJSChart += "var wrapper = new google.visualization.ChartWrapper({\n";
                strJSChart += "chartType: 'ColumnChart',\n";
                strJSChart += "dataTable: [['', 'Gastrointestinal', 'Respiratory', 'Rash', 'Other'],";
                strJSChart += "['', " + daily_summary.Gastrointestinal + ", " + daily_summary.Respiratory + ", " + daily_summary.Rash + ", " + daily_summary.OtherIllness + "]],\n";
                strJSChart += "options: {'title': 'Types of Illnesses'},\n";
                strJSChart += "containerId: 'visualization'\n";
                strJSChart += "});\n";
                strJSChart += "wrapper.draw();\n";
                strJSChart += "}\n\n";

                strJSLoad += "drawSymptoms();\n";
                litTypesOfSymptomsChartGoogle.Text = "<div id=\"visualization\" style=\"width: 600px; height: 400px;\"></div>";
                // *********************************************************************

                // ******************* google chart -- absentee rate *******************
                strJSChart += "function drawAbsenteeRates() {\n";
                strJSChart += "var dataAbsenteeRates = new google.visualization.DataTable();\n";
                strJSChart += "dataAbsenteeRates.addColumn('string', 'Date');\n";
                strJSChart += "dataAbsenteeRates.addColumn('number', 'School Daily Absentee Rate');\n";
                strJSChart += "dataAbsenteeRates.addColumn({type:'string', role:'annotation'});\n";
                strJSChart += "dataAbsenteeRates.addColumn({type:'string', role:'annotationText'});\n";
                strJSChart += "dataAbsenteeRates.addColumn('number', 'School Moving Average Absentee Rate');\n";
                strJSChart += "dataAbsenteeRates.addRows([\n";
                int l = 0;
                string prior_status_html = string.Empty;
                foreach (var r in d_data)
                {
                    if (l < d_data.Count && l > 0)
                        strJSChart += ",\n";
                    string curr_chart_date = r.data_date.ToString("M/d/yyyy");
                    if (r.data_date == curr_date)
                    {
                        strJSChart += "['" + String.Format("{0:d}", curr_chart_date) + "', " + Math.Round(r.rate, 2) + ", 'Report Date', '" + r.data_date.ToString("M/d/yyyy") + "', " + Math.Round(r.moving_rate_std, 2) + "]";
                    }
                    else
                    {
                        strJSChart += "['" + String.Format("{0:d}", curr_chart_date) + "', " + Math.Round(r.rate, 2) + ", null, null, " + Math.Round(r.moving_rate_std, 2) + "]";
                    }

                    // build list of prior school day status indicators
                    prior_status_html += "<tr><td>" + String.Format("{0:d}", curr_chart_date) + "</td>";
                    if (r.a_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-red\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"white\">3 Sigma Warning <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else if (r.b_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-orange\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"white\">Sustained 2-3 Sigma Watch <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else if (r.c_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-lime\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"black\">Consistently Above Mean Watch <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else if (r.d_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-blue\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"white\">Sustained Above 1 Sigma Alert <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else if (r.e_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-purple\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"white\">Sustained Increase Alert <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else if (r.f_warning == true)
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\"><a class=\"btn btn-green\" href=\"javascript:openSchoolWindowGeneric('/manage/school-districts/school-default.aspx?schoolID=" + r.school_id + "&currDate=" + r.data_date + "')\"><font color=\"white\">2 Sigma Alert <i class=\"icon-warning-sign\"></i></font></a></td>";
                    }
                    else
                    {
                        prior_status_html += "<td width=\"70%\" align=\"center\">Normal <i class=\"icon-ok-sign\"></i></font></td>";
                    }
                    prior_status_html += "</tr>";
                    l++;
                }
                litSchoolStatusPrior.Text = prior_status_html;

                strJSChart += "\n]);\n";

                strJSChart += "var options = {\n";
                strJSChart += "title: '" + school.School + " Absenteeism Trends',\n";
                strJSChart += "hAxis: {title: '" + mode_x_axis + "', slantedText: true},\n";
                strJSChart += "vAxis: {title: 'School Absentee Rate (%)'},\n";
                strJSChart += "height: 500\n";
                strJSChart += "};\n";

                strJSChart += "var chart = new google.visualization.LineChart(document.getElementById('visualizationAbsenteeRate'));\n";
                strJSChart += "chart.draw(dataAbsenteeRates, options);\n";
                strJSChart += "}\n";

                strJSLoad += "drawAbsenteeRates();\n";
                lit28DaSchoolRateChart.Text = "<div id=\"visualizationAbsenteeRate\" style=\"height: 600px;\"></div>";
                // *********************************************************************

                // add all finalized JS
                string finalJSLoad = "google.load(\"visualization\", \"1.1\", {packages:[\"corechart\"]});\n";
                finalJSLoad += "google.setOnLoadCallback(init);\n\n";
                finalJSLoad += "function init() {\n";
                finalJSLoad = finalJSLoad + strJSLoad + "\n}\n\n";

                litJSChart.Text = strJSChart;

                // finalize load code
                litJSLoad.Text = "<script type=\"text/javascript\">\n" + finalJSLoad + "</script>";

                int a_e_warnings = 0;

                string warnings_html = string.Empty;
                string text = string.Empty;
                warnings_html += "<ul>";

                string warning_type = string.Empty;
                string warning_message = string.Empty;
                string tip_message = string.Empty;
                string warning_label = string.Empty;
                string warning_color = string.Empty;
                string warning_html_color = string.Empty;
                string font_color = "white";

                tip_message = daily_summary.School;
                warning_message = daily_summary.School;

                if (daily_summary.A_Warning == true)
                {
                    warning_type = "3 sigma warning";
                    warning_message += " (3 sigma warning is triggered for a school when current day absentee rate is greater than 3 sigma of the absentee rate)";
                    tip_message += " Data = [current day absentee rate = " + daily_summary.Rate + ", 3 sigma absentee rate = " + daily_summary.A_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    warning_label = "btn-red";
                    warning_color = "btn-red";
                    warning_html_color = "#e51400";
                    a_e_warnings++;
                }
                else if (daily_summary.B_Warning == true)
                {
                    if (!String.IsNullOrEmpty(warning_type))
                        warning_type += ", Sustained 2-3 Sigma Watch";
                    else
                        warning_type = "Sustained 2-3 Sigma Watch";
                    warning_message += " (Sustained 2-3 Sigma Watch is triggered for a school when the 2 of the prior 3 absentee rates exceed 2 sigma of the absentee rate)";
                    tip_message += " Data = [current day absentee rate = " + daily_summary.Rate + ", 2 sigma absentee rates = " + daily_summary.B_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    a_e_warnings++;
                    warning_label = "btn-orange";
                    warning_html_color = "#f8a31f";
                    warning_color = "btn-orange";
                }
                else if (daily_summary.C_Warning == true)
                {
                    if (!String.IsNullOrEmpty(warning_type))
                        warning_type += ", Consistently Above Mean Watch";
                    else
                        warning_type = "Consistently Above Mean Watch";
                    warning_message += " (Consistently Above Mean Watch is triggered for a school when at least 4 of the 5 prior absentee rates all exceed 1 sigma of the absentee rate)";
                    tip_message += " Data = [current day absentee rate = " + daily_summary.Rate + ", 1 sigma absentee rates = " + daily_summary.C_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    a_e_warnings++;
                    warning_label = "btn-lime";
                    warning_html_color = "#ffff00";
                    font_color = "black";
                }
                else if (daily_summary.F_Warning == true)
                {
                    if (!String.IsNullOrEmpty(warning_type))
                        warning_type += ", 2 Sigma Alert";
                    else
                        warning_type = "2 Sigma Alert";
                    warning_message += " (2 Sigma Alert triggered for a school when current day absentee rate is greater than 2 sigma of the absentee rate)";
                    tip_message += " Data = [current day absentee rate = " + daily_summary.Rate + ", 2 sigma absentee rate = " + daily_summary.F_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    a_e_warnings++;
                    warning_html_color = "#393";
                    warning_label = "btn-green";
                }
                else if (daily_summary.D_Warning == true)
                {
                    if (!String.IsNullOrEmpty(warning_type))
                        warning_type += ", Sustained Above 1 Sigma Alert";
                    else
                        warning_type = "Sustained Above 1 Sigma Alert";
                    warning_message += " (Sustained Above 1 Sigma Alert is triggered for a school when the 8 prior absentee rates are greater than the historic absentee rate)";
                    tip_message += " Data = [historic absentee rate = " + daily_summary.HistoricRate + ", 8 days prior absentee rates = " + daily_summary.D_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    a_e_warnings++;
                    warning_html_color = "#368ee0";
                    warning_label = "btn-blue";
                }
                else if (daily_summary.E_Warning == true)
                {
                    if (!String.IsNullOrEmpty(warning_type))
                        warning_type += ", Sustained Increase Alert";
                    else
                        warning_type = "Sustained Increase Alert";
                    warning_message += " (Sustained Increase Alert is triggered for a school when the 6 prior absentee rates are all increasing)";
                    tip_message += " Data = [current day absentee rate = " + daily_summary.Rate + ", 8 days prior absentee rates = " + daily_summary.E_WarningValues + "]";
                    //warnings_html += "<li> <span class=\"label label-important\">" + warning_type + "</span> <a href=\"#\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_message + " <i class=\"icon-exclamation-sign\"></i></li>";
                    a_e_warnings++;
                    warning_html_color = "#a200ff";
                    warning_label = "btn-purple";
                }

                if (!String.IsNullOrEmpty(warning_type))
                {
                    if (font_color == "black")
                        warnings_html += "<li><div style=\"height:30px!important;\"><a href=\"#\" rel=\"popover\" class=\"btn " + warning_label + " btn-small\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + warning_message + ": " + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\"><font color=\"black\">" + warning_type + "&nbsp;&nbsp;<i class=\"icon-info-sign\"></i></font></a> " + warning_message + " " + tip_message + "</div></li>";
                    else
                        warnings_html += "<li><div style=\"height:30px!important;\"><a href=\"#\" rel=\"popover\" class=\"btn " + warning_label + " btn-small\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + warning_message + ": " + tip_message + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_type + "&nbsp;&nbsp;<i class=\"icon-info-sign\"></i></a> " + warning_message + " " + tip_message + "</div></li>";
                }

                if (a_e_warnings > 0)
                {
                    warnings_html += "</ul>";
                    litHealthWarnings.Text = warnings_html;
                }

                litNumAbsenteeWarnings.Text = "<span class=\"badge\">" + a_e_warnings + "</span>";

                qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(daily_summary.SchoolDistrictID);

                // symptom warnings
                string s_warning_type = string.Empty;
                string s_tip_message = string.Empty;
                string s_warnings_html = string.Empty;
                int num_symptom_warnings = 0;

                string currentStatus = "normal";
                plhStatusNormal.Visible = false;
                plhStatusCaution.Visible = false;
                plhStatusWarning.Visible = false;
                string currStatusDescription = string.Empty;

                string tip_data = string.Empty;
                if (daily_summary.GastrointestinalStatus == "red")
                {
                    warning_type = "Gastrointestinal Warning";
                    tip_message += "A Gastrointestinal warning is triggered for a school when gastroinstestinal-related absenses make up " + variables.RedGastrointestinalBoundary + "% or more of all reported absenses.";
                    tip_data = daily_summary.School + " Gastrointestinal-related absenses on " + String.Format("{0:d}", curr_date) + " = " + Math.Round(daily_summary.GastrointestinalRate, 2) + "%";
                    num_symptom_warnings++;
                }
                if (daily_summary.RashStatus == "red")
                {
                    warning_type = "Rash Warning";
                    tip_message += "A Rash warning is triggered for a school when rash-related absenses make up " + variables.RedRashBoundary + "% or more of all resported absenses.";
                    tip_data = daily_summary.School + " Rash-related absenses on " + String.Format("{0:d}", curr_date) + " = " + Math.Round(daily_summary.RashRate, 2) + "%"; ;
                    num_symptom_warnings++;
                }
                if (daily_summary.RespiratoryStatus == "red")
                {
                    warning_type = "Respiratory Warning";
                    tip_message += "A Respiratory warning is triggered for a school when respiratory-related absenses make up " + variables.RedRespiratoryBoundary + "% or more of all reported absenses.";
                    tip_data = daily_summary.School + " Respiratory-related absenses on " + String.Format("{0:d}", curr_date) + " = " + Math.Round(daily_summary.RespiratoryRate, 2) + "%";
                    num_symptom_warnings++;
                }

                if (!String.IsNullOrEmpty(warning_type))
                {
                    s_warnings_html += "<li><div style=\"height:30px!important;\"><a href=\"#\" class=\"btn btn-darkblue btn-small\" rel=\"popover\" data-trigger=\"hover\" data-placement=\"left\" title=\"\" data-content=\"" + tip_message + " " + tip_data + "\" data-original-title=\"" + warning_type + " at " + daily_summary.School + "\">" + warning_type + "&nbsp;&nbsp;<i class=\"icon-info-sign\"></i></a>";
                    s_warnings_html += "</div></li>";
                }
                if (a_e_warnings > 0)
                {
                    currentStatus = "warning";
                    currStatusDescription += "There are absentee warnings.<br>";
                }

                litNumSymptomWarnings.Text = "<span class=\"badge\">" + num_symptom_warnings + "</span>";

                string status_text = "School Status for <strong>" + String.Format("{0:M/d/yyyy}", curr_date) + "</strong><br><br>";
                if (currentStatus == "normal")
                {
                    plhStatusNormal.Visible = true;
                    currStatusDescription = "There are no absentee or symptom warnings. All other trends appear to be normal.";
                }
                //else if (currentStatus == "caution")
                //{
                //    plhStatusCaution.Visible = true;
                //    currStatusDescription = "There are illness symptom trends of concern.";
                //}
                else if (currentStatus == "warning")
                {
                    plhStatusWarning.Visible = true;
                    litWarningStatusColor.Text = "bgcolor=\"" + warning_html_color + "\"";
                    litWarningFooter.Text = warning_type;
                }
                litNormalHeader.Text = status_text;
                litCautionHeader.Text = status_text;
                litWarningHeader.Text = status_text;
                litStatusDescription.Text = "<i class=\"icon-info-sign\"></i> " + currStatusDescription;
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (school_district_id == 0)
                school_district_id = 1;

            qHtl_AbsenteeAnalysisVariable variables = new qHtl_AbsenteeAnalysisVariable(school_district_id);

            if (summary == null)
            {
                if (String.IsNullOrEmpty(Request.QueryString["currDate"]))
                {
                    summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetMostRecentDailySummary();
                }
                else
                {
                    string eval_curr_date = Convert.ToString(Request.QueryString["currDate"]);
                    summary = qHtl_DailySchoolDistrictAbsenteeSummary.GetDailySummaryByDate(eval_curr_date);
                }
            }

            if (summary != null)
            {
                if (summary.DailySchoolDistrictAbsenteeSummaryID > 0)
                {
                    DateTime curr_date = new DateTime();
                    curr_date = Convert.ToDateTime(summary.DataDate);
                    litMostRecentDate.Text = String.Format("{0:MMMM d, yyyy}", curr_date);
                    litEnrolled.Text = String.Format("{0:0,0}", summary.TotalEnrolled);
                    litAbsences.Text = String.Format("{0:0,0}", summary.TotalAbsent);

                    int total_illness = summary.Gastrointestinal + summary.Rash + summary.Respiratory + summary.Rash + summary.OtherIllness;
                    int total_unknown = summary.TotalAbsent - total_illness;
                    litIllness.Text = String.Format("{0:0,0}", total_illness);
                    litUnknown.Text = String.Format("{0:0,0}", total_unknown);
                    litRate.Text = Convert.ToString(Math.Round(summary.OverallAbsenteeRate, 2));
                    litMovingAverage.Text = Convert.ToString(Math.Round(summary.HistoricAbsenteeRate, 2));

                    decimal num_gast = Convert.ToDecimal(summary.Gastrointestinal);
                    decimal num_resp = Convert.ToDecimal(summary.Respiratory);
                    decimal num_rash = Convert.ToDecimal(summary.Rash);
                    decimal num_othr = Convert.ToDecimal(summary.OtherIllness);
                    decimal num_illness_total = num_gast + num_resp + num_rash + num_othr;

                    decimal percent_gast = 0;
                    decimal percent_resp = 0;
                    decimal percent_rash = 0;
                    decimal percent_othr = 0;

                    if (num_gast > 0)
                    {
                        percent_gast = num_gast / num_illness_total;
                        percent_gast = percent_gast * 100;
                    }
                    if (num_resp > 0)
                    {
                        percent_resp = num_resp / num_illness_total;
                        percent_resp = percent_resp * 100;
                    }
                    if (num_rash > 0)
                    {
                        percent_rash = num_rash / num_illness_total;
                        percent_rash = percent_rash * 100;
                    }
                    if (num_othr > 0)
                    {
                        percent_othr = num_othr / num_illness_total;
                        percent_othr = percent_othr * 100;
                    }
                    litGastBar.Text = "style=\"width:" + percent_gast + "%\"";
                    litRespBar.Text = "style=\"width:" + percent_resp + "%\"";
                    litRashBar.Text = "style=\"width:" + percent_rash + "%\"";
                    litOthrBar.Text = "style=\"width:" + percent_othr + "%\"";

                    litGastrointestinal.Text = "(" + Convert.ToString(summary.Gastrointestinal) + ")";
                    litRespiratory.Text = "(" + Convert.ToString(summary.Respiratory) + ")";
                    litRash.Text = "(" + Convert.ToString(summary.Rash) + ")";
                    litOtherIllness.Text = "(" + Convert.ToString(summary.OtherIllness) + ")";

                    litProcessed.Text = Convert.ToString(summary.Created);

                    if (num_warnings > 0)
                        litNumWarnings.Text = "<a href=\"/manage/school-districts/school-health-warnings.aspx\">" + num_warnings + " A-E Warnings</a>";
                    else
                    {
                        int num_a_e_warnings = 0;

                        num_a_e_warnings = qHtl_DailySchoolAbsenteeData.CountNumberAEWarningsByDate(Convert.ToDateTime(summary.DataDate));

                        if (num_a_e_warnings > 0)
                            litNumWarnings.Text = "<i class=\"icon-warning-sign\"></i> <strong>(" + num_a_e_warnings + ")</strong> Absentee Warnings";
                        else
                            litNumWarnings.Text = "No warnings for this date";
                    }
                }
            }
        }
    }