public string getExcelPathByTypeArea(string DataType, string PointNo, string StartDate, string EndDate) { string[][] DatePointNoList; List <string> AllDateList = new List <string>(); List <string> PointNoList = new List <string>(); string FileNameTarget = DataType + "-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xlsx"; string FileNameTemplate = DataType + ".xlsx"; string ProjectName = HttpContext.Current.Session["showProjects"].ToString(); string makeFilePathTemplate = HttpContext.Current.Server.MapPath("../Projects/" + ProjectName + "/Data/").ToString() + FileNameTemplate; string makeFilePathTarget = HttpContext.Current.Server.MapPath("../Projects/" + ProjectName + "/Data/").ToString() + FileNameTarget; string FrontPath = "../Projects/" + ProjectName + "/Data/" + FileNameTarget; StartDate += " 00:00:00"; EndDate += " 23:59:59"; AllDateList = this.GetDateList(DataType, StartDate, EndDate, PointNoList); DatePointNoList = this.GetPointNoData(PointNo, DataType, StartDate, EndDate); if (DatePointNoList.Length == 0) { return("non"); } if (ExcelWritter.writeExcel(DatePointNoList, PointNo, makeFilePathTarget, DataType, makeFilePathTemplate)) { return(FrontPath); } else { return("non"); } }
//Boss/玩家死亡 public void GameOver(int RewardScore) { GameOverUI.SetActive(true); Time.timeScale = 0; if (isWin) { WinSprie.sprite = WinSprite; NextGameButton.interactable = true; } else { WinSprie.sprite = LoseSprite; NextGameButton.interactable = false; } //遊戲結束Level GameOverLevelImage[0].sprite = NumberSprite[int.Parse(LevelIDString.Substring(1, 1))]; GameOverLevelImage[1].sprite = NumberSprite[int.Parse(LevelIDString.Substring(0, 1))]; //遊戲結束總分=遊戲分數+獎勵分數; GameOverScore = TotalScore + RewardScore; GameOverScoreString = GameOverScore + ""; RewardScoreString = RewardScore + ""; for (int i = RewardScoreImage.Count; i < RewardScoreString.Length; i++) { //動態生成Image GameObject RewardScorePrefab = Instantiate(ScoreObject) as GameObject; //將生成出來Image移動到空物件階層下 RewardScorePrefab.transform.parent = RewardScoreGridObject.transform; //抓取動態生成物件的Image存放在list RewardScoreImage.Add(RewardScorePrefab.GetComponent <Image>()); } //將每個Image帶入數字圖片 for (int spritID = 0; spritID < RewardScoreString.Length; spritID++) { RewardScoreImage[spritID].sprite = NumberSprite[int.Parse(RewardScoreString.Substring(spritID, 1))]; } for (int i_g = GameOverScoreImage.Count; i_g < GameOverScoreString.Length; i_g++) { //動態生成Image GameObject GameOverScorePrefab = Instantiate(ScoreObject) as GameObject; //將生成出來Image移動到空物件階層下 GameOverScorePrefab.transform.parent = GameOverScoreGridObject.transform; //抓取動態生成物件的Image存放在list GameOverScoreImage.Add(GameOverScorePrefab.GetComponent <Image>()); } //將每個Image帶入數字圖片 for (int spritID_g = 0; spritID_g < GameOverScoreString.Length; spritID_g++) { GameOverScoreImage[spritID_g].sprite = NumberSprite[int.Parse(GameOverScoreString.Substring(spritID_g, 1))]; } //將資料寫入至Excel表單 ExcelWritter.ansList.Add(LevelIDString); ExcelWritter.ansList.Add(GameOverScoreString); //寫入Excel檔名與表單名稱 ExcelWritter.WriteExcel("SaveData", "Data"); }
//將資料寫入EXCEL(Excel名稱,表單名稱) public static void WriteExcel(string ExcelName, string SheetName) { //自定義Excel位置 string Path = Application.streamingAssetsPath + "/" + ExcelName + ".xlsx"; FileInfo newFile = new FileInfo(Path); //透過ExcelPackage開啟Excel表單 using (ExcelPackage package = new ExcelPackage(newFile)) { //讀取Excel中的Sheet表單 ExcelWorksheet worksheet; worksheet = package.Workbook.Worksheets[SheetName]; //讀取Excel表格內那些地區已有資料,接續從該筆資料下方繼續寫入新資料 float collect = ExcelWritter.ReadExcel(Path, SheetName).Count; //新增一行資料需要花費的時間 worksheet.Cells["A" + (collect + 1)].Value = timer; //抓取要填入資料的表單代號[A...],例如要寫入的資料只有三個欄位,就代表Excel裡的[A、B、C],可自行增加與修改要寫入的資料欄位 //假設此案只儲存LevelID和Total Score for (int i = 0; i < 2; i++) { //表格代號 string letter = ""; switch (i) { case 0: letter = "A"; break; case 1: letter = "B"; break; } //將資料帶入表格內,如果是第一個位置資料 //worksheet.Cells[letter+"1"].Value=要帶入的資料=worksheet.Cells["A1"].Value=要帶入的資料 worksheet.Cells[letter + (collect + 1)].Value = ExcelWritter.ansList[i]; } //儲存Excel; package.Save(); //將帶入Excel內的ansList List資料清除,以免資料堆砌 ExcelWritter.ansList.Clear(); } }
static void Main(string[] args) { System.Console.WriteLine("Welcome to the Kaplan-Meier estimator program!"); SetParams(); var patientReader = new ExcelPatientReader(Path.Combine(Directory.GetCurrentDirectory(), PatientFileName), PatientSheetName, hasHeader: true); patientReader.RegisterParser(@"Patientnummer", (value, patient) => patient.Id = int.Parse(value)); patientReader.RegisterParser(@"EventFreeSurvival_event (metastasis or death)", (value, patient) => patient.CensorEvent = (EventFreeSurvival)Enum.Parse(typeof(EventFreeSurvival), value)); patientReader.RegisterParser(@"reg_t_fu_months", (value, patient) => patient.CensorEventTime = (int)Math.Floor(double.Parse(value))); var geneReader = new CSVGeneReader(Path.Combine(Directory.GetCurrentDirectory(), GeneFileName)); var patients = patientReader.ReadToEnd().ToDictionary(patient => patient.Id); var genes = geneReader.GetGenes().ToList(); ISplitStrategy[] splitStrategies = null; if (Time == "before") { splitStrategies = new ISplitStrategy[] { new T0_TopNPercentSplitStrategy(Percentile, patients) }; } if (Time == "after") { splitStrategies = new ISplitStrategy[] { new T2_TopNPercentSplitStrategy(Percentile, patients) }; } if (Time == "diff") { splitStrategies = new ISplitStrategy[] { new T0T2Diff_TopNPercentSplitStrategy(Percentile, patients) }; } string currentDir = Directory.GetCurrentDirectory(); foreach (var strategy in splitStrategies) { if (Directory.Exists(Path.Combine(currentDir, strategy.Name))) { Directory.Delete(Path.Combine(currentDir, strategy.Name), true); } DirectoryInfo targetDir = Directory.CreateDirectory(Path.Combine(currentDir, strategy.Name)); if (!targetDir.Exists) { targetDir.Create(); } StrategyRunner runner = new StrategyRunner(strategy); var orderedResults = runner.Run(genes).ToArray(); int resultsCount = orderedResults.Length; for (int index = 0; index < resultsCount; index++) { var result = orderedResults[index]; result.FDR = (result.Estimate.PValue * resultsCount) / (index + 1); } File.WriteAllText(Path.Combine(targetDir.FullName, "Results.csv"), "Illumina ID, P-Value, -Log(P-Value), FDR, GroupSize" + Environment.NewLine); File.AppendAllLines(Path.Combine(targetDir.FullName, "Results.csv"), orderedResults.Select((result, index) => string.Format("{0}, {1:E}, {2}, {3}, {4}", result.GeneId, result.Estimate.PValue, -Math.Log10(result.Estimate.PValue), (result.Estimate.PValue * resultsCount) / (index + 1), result.GroupSize))); var logRankDir = targetDir.CreateSubdirectory("Results_LogRank"); ExcelWritter excelOutput = new ExcelWritter(logRankDir, orderedResults, result => - Math.Log10(result.Estimate.PValue)); excelOutput.WriteExcelFiles(); orderedResults = orderedResults.OrderBy(result => result.FDR).ToArray(); var fdrRankDir = targetDir.CreateSubdirectory("Results_FDR"); excelOutput = new ExcelWritter(fdrRankDir, orderedResults, result => result.FDR); excelOutput.WriteExcelFiles(); System.Console.WriteLine("Output is ready at {0}", targetDir.FullName); System.Console.ReadLine(); } }