def get_district_subject_std_values(subject_name, table_code):
    wheres = [school_where, exam_where]
    if subject_name == "总分":
        stu_table = table_config.get_stu_sum_table(table_code)
        school_table = table_config.get_school_sum_table(table_code)
    else:
        stu_table = table_config.get_stu_dimen_table(table_code)
        school_table = table_config.get_school_dimen_table(table_code)

        subject_where.set_value(get_subject_id_by_name(subject_name))
        wheres.append(subject_where)

    subject_total = report_config.get_total(subject_name)

    xresult = []
    yresult = []

    school_subject_num_cell = qa.Cell("num_nz", school_table, wheres)
    school_subject_num_row = qa.RowSeriesCell(school_subject_num_cell, school_ids)

    school_subject_avg_cell = qa.Cell("ROUND(avg / %d, 2)" % subject_total, school_table, wheres)
    school_subject_avg_row = qa.RowSeriesCell(school_subject_avg_cell, school_ids)

    stu_subject_sum_cell = qa.Cell("sum", stu_table, wheres)
    stu_subject_sum_row = qa.ColSeriesCell(stu_subject_sum_cell, school_ids)

    for value in stu_subject_sum_row.get_values():
        yresult.append(round(np.std(value, ddof=1), 2))
    xresult = school_subject_avg_row.get_values()[0]
    num = school_subject_num_row.get_values()[0]
    return xresult, yresult, num
def get_district_subject_distribution_values(subject_name, ids, table_code):
    distribution = report_config.get_distribution(subject_name)
    statistics_type = distribution[0]

    greater_where = qa.Where("sum", symbol=">")
    less_equal_where = qa.Where("sum", symbol="<=")

    basic_where = [exam_where]
    if subject_name == "总分":
        dimen_table = table_config.get_stu_sum_table(table_code)
        if statistics_type == report_config.COUNT:
            basic_where.append(qa.Where("count", value=distribution[2]))
    else:
        dimen_table = table_config.get_stu_dimen_table(table_code)
        subject_where.value = get_subject_id_by_name(subject_name)
        basic_where.append(subject_where)

    normal_cell = qa.Cell("COUNT(*)", dimen_table, [[greater_where, less_equal_where]] + basic_where)
    if statistics_type == report_config.ALL:
        greater_equal_where = qa.Where("sum", symbol=">=")
        extra_cell = qa.Cell("COUNT(*)", dimen_table, [[greater_equal_where, less_equal_where]] + basic_where)
        row1 = qa.RowSeriesCell(extra_cell, ids[0:1])
        row2 = qa.RowSeriesCell(normal_cell, ids[1:])
        return qa.DataRows.combine_col_rows(row1, row2)
    else:
        row = qa.RowSeriesCell(normal_cell, ids)
        return row.get_values()
def get_district_subject_std_values(subject_name, type_code, table_code):
    wheres = [school_where, exam_where]
    if subject_name == "总分":
        stu_table = table_config.get_stu_sum_table(table_code)
        school_table = table_config.get_school_table(type_code)[1]
    else:
        stu_table = table_config.get_stu_dimen_table(table_code)
        school_table = table_config.get_school_table(type_code)[0]

        subject_where.set_value(get_subject_id_by_name(subject_name))
        wheres.append(subject_where)

    subject_total = report_config.get_total(subject_name)

    xresult = []
    yresult = []

    school_subject_num_cell = qa.Cell("num_nz", school_table, wheres)
    school_subject_num_row = qa.RowSeriesCell(school_subject_num_cell,
                                              school_ids)
    for school_id in school_ids:
        school_where.set_value(school_id)
        school_subject_avg_cell = qa.Cell("avg", school_table, wheres)
        stu_subject_sum_cell = qa.Cell("sum", stu_table, wheres)
        xresult.append(
            round(school_subject_avg_cell.get_value() / subject_total, 2))
        yresult.append(
            round(np.std(stu_subject_sum_cell.get_row_values(), ddof=1), 2))
    num = school_subject_num_row.get_values()[0]
    return xresult, yresult, num
def get_district_subject_box_values(subject_name, table_code):
    wheres = [school_where, exam_where]
    if subject_name == "总分":
        stu_table = table_config.get_stu_sum_table(table_code)
    else:
        stu_table = table_config.get_stu_dimen_table(table_code)
        subject_where.set_value(get_subject_id_by_name(subject_name))
        wheres.append(subject_where)
    stu_subject_sum_cell = qa.Cell("sum", stu_table, wheres)
    stu_subject_sum_row = qa.ColSeriesCell(stu_subject_sum_cell, school_ids)
    return stu_subject_sum_row.get_values()