public static DiffInfo GetDiffInfoFromJObj(int diff, JObject obj) { DiffInfo result = new DiffInfo(); if (obj == null || !obj.HasValues) { result.diff = Constants.SongMark.Difficulty[diff]; return(result); } result.diff = obj["music_level"].Value <String>(); result.rating = obj["rating"].Value <String>(); result.score = obj["score"].Value <int>(); result.chain_max = obj["max_chain"].Value <int>(); if (obj["perfect"].Value <int>() != 0) { result.chain_status = 3; } else if (obj["full_chain"].Value <int>() != 0) { result.chain_status = 2; } else if (obj["no_miss"].Value <int>() != 0) { result.chain_status = 1; } result.clear = (obj["is_clear_mark"].Value <bool>() || !obj["is_failed_mark"].Value <bool>()); result.play_count = obj["play_count"].Value <int>(); return(result); }
public void SetDiffData(int diff, int pc, String rating, int score, bool clear, int chain_status, int chain_max) { DiffInfo data = new DiffInfo(); data.play_count = pc; data.rating = rating; data.score = score; data.clear = clear; data.chain_status = chain_status; data.chain_max = chain_max; scores.Add(diff, data); }
public override string ToString() { StringBuilder sb = new StringBuilder("\nSong: "); sb.Append(title).Append(" (").Append(id).Append(")\n\n"); for (int i = 0; i < scores.Count; i++) { if (i != 0) { sb.Append("\n\n"); } DiffInfo s = scores[i]; sb.Append(s); } sb.Append(Constants.divider + "\n"); return(sb.ToString()); }
public void SetDiffData(int diff, DiffInfo info) { scores.Add(diff, info); }
public void BackupScores(Boolean self, String friendHash, int mode) { DateTime t0 = DateTime.Now; var resp = client.GetData(Constants.URL.MusicList); // log.Debug(Util.JsonToString(resp)); Dictionary <int, ArrayList> data = new Parser().ParseMusicListJson(resp); log.Info("Music list length = " + data.Keys.Count); List <SongInfo> songs = new List <SongInfo>(); ArrayList threads = new ArrayList(); ArrayList runningFetchers = new ArrayList(); int RunningJobs = 0; // use some threads to fetch all the scores from list foreach (int id in data.Keys) { log.Info("Fetching (" + id + "). " + data[id][0]); ScoreFetcher f = new ScoreFetcher(client, id, self, (int)data[id][1], (String)data[id][2]); Thread t = new Thread(f.run); t.Start(); runningFetchers.Add(f); threads.Add(t); ++RunningJobs; // Executing thread amount reached limit, wait for the first thread in list to finish if (RunningJobs >= Constants.Threads) { ((Thread)threads[0]).Join(); songs.Add(((ScoreFetcher)runningFetchers[0]).GetSongInfo()); runningFetchers.RemoveRange(0, 1); threads.RemoveRange(0, 1); --RunningJobs; // if (songs.Count > 10) break; // faster testing } } foreach (Thread t in threads) { t.Join(); } foreach (ScoreFetcher f in runningFetchers) { songs.Add(f.GetSongInfo()); } String name = (DateTime.Today.ToString()).Replace("/", "_").Split(' ')[0]; if (mode == 0) { name += ".txt"; File.Create(name).Dispose(); File.WriteAllText(name, ""); foreach (SongInfo si in songs) { log.Info(si.ToString()); File.AppendAllText(name, si.ToString(), Encoding.UTF8); } } else { ExcelPackage.LicenseContext = LicenseContext.NonCommercial; name += ".xlsx"; ExcelPackage xls = new ExcelPackage(); ExcelWorksheet sheet = xls.Workbook.Worksheets.Add("Scores"); String[] heading = { "ID", "TITLE", "SIMPLE\nMARK", "SIMPLE\nRATING", "SIMPLE\nSCORE", "SIMPLE\nCHAIN", "SIMPLE\nPLAYS", "SIMPLE\nRANK", "NORMAL\nMARK", "NORMAL\nRATING", "NORMAL\nSCORE", "NORMAL\nCHAIN", "NORMAL\nPLAYS", "NORMAL\nRANK", "HARD\nMARK", "HARD\nRATING", "HARD\nSCORE", "HARD\nCHAIN", "HARD\nPLAYS", "HARD\nRANK", "EXTRA\nMARK", "EXTRA\nRATING", "EXTRA\nSCORE", "EXTRA\nCHAIN", "EXTRA\nPLAYS", "EXTRA\nRANK", "TIMESTAMP", "FAVORITE" }; Char col = 'A'; try { for (int i = 0; i < 26; i++) { sheet.Cells[col++ + "1"].Value = heading[i]; } sheet.Cells["AA1"].Value = heading[26]; sheet.Cells["AB1"].Value = heading[27]; sheet.View.FreezePanes(2, 1); } catch (TypeLoadException e) { log.Debug("current col = " + col); log.Debug(e.StackTrace); } log.Debug("heading all set"); int row = 2; foreach (SongInfo si in songs) { sheet.Cells["A" + row].Value = si.GetID(); sheet.Cells["B" + row].Value = si.GetTitle(); col = 'C'; for (int i = 0; i < (si.HasEx() ? 4 : 3); i++) { DiffInfo score = si.GetDiff(i); if (score.score == -1) { sheet.Cells[(col).ToString() + row].Value = "NOT PLAYED"; ++col; ++col; ++col; ++col; ++col; ++col; // col += 6; continue; } sheet.Cells[(col++).ToString() + row].Value = Constants.SongMark.ChainStatus[score.chain_status]; sheet.Cells[(col++).ToString() + row].Value = score.rating; sheet.Cells[(col++).ToString() + row].Value = score.score; sheet.Cells[(col++).ToString() + row].Value = score.chain_max; sheet.Cells[(col++).ToString() + row].Value = score.play_count; sheet.Cells[(col++).ToString() + row].Value = score.rank; } sheet.Cells["AA" + (row)].Value = si.GetTimestamp(); sheet.Cells["AB" + (row++)].Value = si.IsFavorite() ? "Yes" : "No"; } sheet.Cells["A1:AB1"].Style.WrapText = true; sheet.Row(1).Height = 30; sheet.Cells["A1:AB" + (songs.Count + 1)].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; sheet.Cells["A1:AB" + (songs.Count + 1)].Style.VerticalAlignment = ExcelVerticalAlignment.Center; sheet.Cells["A1:AB" + (row - 1)].AutoFitColumns(20); FileInfo fi = new FileInfo(name); if (fi.Exists) { fi.Delete(); } fi.Create(); xls.SaveAs(fi); log.Info("Elapsed time: " + (DateTime.Now - t0)); } }