= 次數 and current < 次數 + 級距, current >= 次數 and current <= 次數 + 級距 /* 最後一根柱子中要包含最大值 */ ) ).length() ) ), /* 建立平均值和標準差線 */ line_list, "x".repeat(分數區"> = 次數 and current < 次數 + 級距, current >= 次數 and current <= 次數 + 級距 /* 最後一根柱子中要包含最大值 */ ) ).length() ) ), /* 建立平均值和標準差線 */ line_list, "x".repeat(分數區"> = 次數 and current < 次數 + 級距, current >= 次數 and current <= 次數 + 級距 /* 最後一根柱子中要包含最大值 */ ) ).length() ) ), /* 建立平均值和標準差線 */ line_list, "x".repeat(分數區">

科目

圖表設定

考試成績

lets(
    /* 載入圖表設置 */
    級距, prop("圖表設定").at(0).prop("直方圖間距"),
    直方圖最長格數, prop("圖表設定").at(0).prop("直方圖條長度的上限"), 
    顏色, prop("顏色"),
    分數, prop("考試成績").map(current.prop("分數成績")),
    科目最高分, prop("考試成績").map(current.prop("分數成績")).max(分數),
    科目最大值, 100,
	  
    /* 統計 */
    平均値, 分數.sum() / 分數.length(),
    標準差, sqrt(sum(分數.map((current - 平均値) ^ 2)) / 分數.length()), 
    低標準差, 平均値 - 標準差, 
    高標準差, 平均値 + 標準差, 
	
    /* 分數區間顯示格式化 */
    分數區間, "x".repeat(ceil(科目最大值 / 級距)).split("").map(index * 級距),
    分數字符最大長度, 分數區間.max().format().length(),
    分數級距_標示, 分數區間.map("0".repeat(分數字符最大長度 - current.format().length()) + current),
	
    /* 頻率分佈 */
    區間總次數, 分數區間.map(
        let(次數, current,
            分數.filter(
                if(次數 != 分數區間.max(),
                    current >= 次數 and current < 次數 + 級距,
                    current >= 次數 and current <= 次數 + 級距 /* 最後一根柱子中要包含最大值 */
                )
            ).length()
        )
    ),
	
    /* 建立平均值和標準差線 */
    line_list, "x".repeat(分數區間.length() * 2)
                  .split("")
                  .map((index + 1) * 級距 / 2),  /* 分數區間的一半[5,10,15,20....] */
    average_index, line_list.findIndex(平均値 <= current + 級距 / 4),
    s_lower_index, line_list.findIndex(低標準差 <= current + 級距 / 4),
    s_upper_index, line_list.findIndex(高標準差 <= current + 級距 / 4),
    line_info, 分數區間.map(
        [
        /* 平均值線 */
        if(index == floor(average_index / 2),average_index % 2 == 0 ? "s" : "u", ""),
		
        /* 上下標準差線(若平均值也在同一根柱子上,那也會被上色) */
        ifs(
            index == floor(s_lower_index / 2),(s_lower_index % 2 == 0 ? "s," : "u,") + 顏色,
            index == floor(s_upper_index / 2),(s_upper_index % 2 == 0 ? "s," : "u,") + 顏色,
            ""
        ),
		
        /* 是平均值線嗎? */
        if(index == floor(average_index / 2), true, false)
        ]
    ),
	
    
    /* 製作直方圖表 */
    ratio, 直方圖最長格數 / 區間總次數.max(), /* 長度放大倍率 */
    graph, 區間總次數.map(
        let(
            line, line_info.at(index),
		        分數級距_標示.at(index) + " " + /* 輸出刻度值 */
		        if(current==0,
		            "  ".style(line.at(0),line.at(1)), /* 即使柱狀條為 0 也要輸出 */
		            " ".repeat(round(current*ratio))
		               .style(line.at(0), line.at(1), 顏色 + "_background") /* 輸出線和柱狀條 */
		        ) + 
		        if(line.at(2),
		            "  ".style(line.at(0)) + "平均:" + round(平均値 * 10) / 10,
		            ""
		        ) /*平均値を出力*/
        )
    ).join("\\n"),
	
    /* 輸出結果 */
    graph
)