public JsonMajorCollege getScoreThroughYears(string collegeId, string majorId) { List <JsonScore> jsonScores = new List <JsonScore>(); double[] years = _majorCollegeRepository.GetPastYearsTrainData(collegeId, majorId); foreach (var y in years) { JsonScore jc = new JsonScore(); jc.year = Convert.ToInt32(y); MajorCollege majorCollegeScore = this._majorCollegeRepository.GetMajorCollegesByCollegeCodeAndMajorAndYear(collegeId, majorId, y).Result; jc.groupCode = majorCollegeScore.groupCode; jc.score = majorCollegeScore.score; jsonScores.Add(jc); } var collegeName = this._collegeRepository.findByCode(collegeId).Result.name; var majorName = this._majorRepository.findByCode(majorId).Result.name; JsonMajorCollege jsonMajorCollege = new JsonMajorCollege(); jsonMajorCollege.collegeCode = collegeId; jsonMajorCollege.collegeName = collegeName; jsonMajorCollege.majorCode = majorId; jsonMajorCollege.majorName = majorName; jsonMajorCollege.scores = jsonScores; return(jsonMajorCollege); }
private void testDateSingle() { using (var db = new EntranceScoresContext()) { var collegeEntity = db.collegeEntities.DefaultIfEmpty().Single(c => c.code.Equals("ANH")); var majorEntity = db.majorEntities.DefaultIfEmpty().Single(c => c.code.Equals("714")); var majorCollege = new MajorCollege(); majorCollege.CollegeEntity = collegeEntity; majorCollege.MajorEntity = majorEntity; majorCollege.score = 17.5; majorCollege.groupCode = "sdsd"; majorCollege.year = 2019; db.majorColleges.Add(majorCollege); db.SaveChanges(); } }
private async void ProcessCrawling(string url, string collegeCode, int year, EntranceScoresContext db) { string[] log = new string[1000]; HtmlAgilityPack.HtmlWeb webSite = new HtmlAgilityPack.HtmlWeb(); HtmlAgilityPack.HtmlDocument document = webSite.Load(url); try { var html = document.DocumentNode.SelectSingleNode("//div[@class='tabs']"); var tableNode = html.SelectSingleNode("//table"); int i = 0; foreach (HtmlNode row in tableNode.SelectNodes("tr[@class='bg_white']")) { try { //major.Code = row.SelectNodes("td")[1].InnerText; //major.Name = row.SelectNodes("td")[2].InnerText; //major.GroupCode = row.SelectNodes("td")[3].InnerText; //major.Score = double.Parse(row.SelectNodes("td")[4].InnerText); MajorCollege majorCollege = new MajorCollege(); string majorCode = row.SelectNodes("td")[1].InnerText; if (majorCode == "") { continue; } CollegeEntity collegeEntity = null; MajorEntity majorEntity = null; try { collegeEntity = db.collegeEntities.DefaultIfEmpty().Single(c => c.code.Equals(collegeCode)); majorEntity = db.majorEntities.DefaultIfEmpty().Single(c => c.code.Equals(majorCode)); if (collegeEntity == null) { continue; } if (majorEntity == null) { isAddNewMajor = true; MajorEntity newMajor = new MajorEntity(); newMajor.code = majorCode; newMajor.name = row.SelectNodes("td")[2].InnerText; //Check exist //newMajorEntities.Add(newMajor); try { newMajorMap.Add(newMajor.code, newMajor.name); } catch (ArgumentException e) { newMajorMap[newMajor.code] = newMajor.name; } continue; } if (isAddNewMajor == false) { majorCollege.MajorEntity = majorEntity; majorCollege.CollegeEntity = collegeEntity; majorCollege.groupCode = row.SelectNodes("td")[3].InnerText; majorCollege.year = year; majorCollege.score = double.Parse(row.SelectNodes("td")[4].InnerText); majorColleges.Push(majorCollege); } } catch (InvalidOperationException e) { System.Console.WriteLine(e.Message); } i++; } catch (FormatException e) { System.Console.WriteLine(e.Message); } } }catch (NullReferenceException e) { System.Console.WriteLine(e.Message); } }