protected void Page_Load(object sender, EventArgs e) { string filepath1 = @"data/000001.csv"; string filepath2 = @"data/600519.csv"; classCSVHelper csh = new classCSVHelper(); filepath1 = Server.MapPath(filepath1); filepath2 = Server.MapPath(filepath2); DataTable dt1 = csh.readCsvSql(filepath1); DataTable dt2 = csh.readCsvSql(filepath2); double[] closingPrice1 = new double[25]; for (int i = 0; i < 25; i++) { closingPrice1[i] = double.Parse(dt1.Rows[i][3].ToString()); Response.Write(string.Format("{0},{1}</br>", i, closingPrice1[i])); } double[] closingPrice2 = new double[25]; for (int i = 0; i < 25; i++) { closingPrice2[i] = double.Parse(dt2.Rows[i][3].ToString()); Response.Write(string.Format("{0},{1}</br>", i, closingPrice2[i])); } double ppcc = calCov(closingPrice1, closingPrice2) / (Caldevar(closingPrice1) * Caldevar(closingPrice2)); Response.Write("相关系数为" + ppcc); }
protected void Button1_Click(object sender, EventArgs e) { string filepath = txtFilePath.Text; classCSVHelper csh = new classCSVHelper(); filepath = Server.MapPath(filepath); DataTable dt1 = csh.readCsvSql(filepath); DataTable dt = csh.readCsvTxt(filepath, Encoding.Default); int i = 0; double[] closingPrice = new double[dt1.Rows.Count]; foreach (DataRow dr in dt1.Rows) { closingPrice[i++] = double.Parse(dr[3].ToString()); } }
protected void Button1_Click(object sender, EventArgs e) { string filepath = @"某公司统计的开机时间17000条左右.csv"; classCSVHelper csh = new classCSVHelper(); filepath = Server.MapPath(filepath); DataTable dt = csh.readCsvTxt(filepath, Encoding.Default); double[] Time = new double[dt.Rows.Count]; int j = 0; //数据清洗 for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i][1].ToString() != "" && double.Parse(dt.Rows[i][1].ToString()) > 0) { Time[j] = double.Parse(dt.Rows[i][1].ToString()); j++; } } //建立新数组,防止出现null值 double[] openTime = new double[j]; for (int i = 0; i < j; i++) { openTime[i] = Time[i]; } double mean = calMean(openTime); double devar = Caldevar(openTime); try { double second = double.Parse(TextBox1.Text); double z = (second - mean) / devar; double rate = 1 - ClassStatistics.selfCaculate(z); Response.Write(string.Format("你的开机速度击败了{0:F}%的成员!", rate * 100)); } catch (Exception ex) { Response.Write(ex.Message); } }