public JsonResult trends(String[] Uni, String Type, String SubType) { TrendsModel Tmodel = new TrendsModel(); Tmodel.answer = new List <TrendsObject>(); String sql = "select * from trends"; String sendSubType = SubType; String sendType = Type; if (Type == "Criminal Offense") { sendType = "CRIMINAL_OFFENSE"; if (SubType == "Burglary") { sendSubType = "BURGLA"; } else if (SubType == "Murder") { sendSubType = "MURD"; } else if (SubType == "Vehicle theft") { sendSubType = "VEHIC"; } else if (SubType == "Man slaughter") { sendSubType = "NEG_M"; } else if (SubType == "Robbery") { sendSubType = "ROBBE"; } else if (SubType == "Forcible Sex offence") { sendSubType = "FORCIB"; } else if (SubType == "non-forcible sex offence") { sendSubType = "NONFOR"; } else if (SubType == "Assault") { sendSubType = "AGG_A"; } else { sendSubType = "ARSON"; } } else if (Type == "Violence Against Women") { sendType = "VAWA"; if (SubType == "Stalking") { sendSubType = "Stalk"; } else if (SubType == "Dating violence") { sendSubType = "Dating"; } else { sendSubType = "Domest"; } } else if (Type == "Arrests") { sendType = "ARRESTS"; if (SubType == "Drug") { sendSubType = "DRUG"; } else if (SubType == "Weapon") { sendSubType = "Weapon"; } else { sendSubType = "Liquor"; } } else { sendType = "DISCIPLINE"; if (SubType == "Drug") { sendSubType = "DRUG"; } else if (SubType == "Weapon") { sendSubType = "Weapon"; } else { sendSubType = "Liquor"; } } using (connection) { connection.Open(); for (int itr1 = 0; itr1 < Uni.Length; itr1++) { OracleCommand cmd0 = new OracleCommand("GENERATETREND", connection); cmd0.CommandType = System.Data.CommandType.StoredProcedure; //cmd0.Parameters.Add(new OracleParameter("TypeFilter", sendType)); //cmd0.Parameters.Add(new OracleParameter("FocusFilter", sendSubType)); //cmd0.Parameters.Add(new OracleParameter("yearFilter", Year)); String[] temp = Uni[itr1].Split(':'); cmd0.Parameters.Add("UniversityFilter", OracleDbType.Varchar2).Value = temp[0]; cmd0.Parameters.Add("BranchFilter", OracleDbType.Varchar2).Value = temp[1]; cmd0.Parameters.Add("CityFilter", OracleDbType.Varchar2).Value = temp[2]; cmd0.Parameters.Add("StateFilter", OracleDbType.Varchar2).Value = temp[3]; cmd0.Parameters.Add("TypeFilter", OracleDbType.Varchar2).Value = sendType; cmd0.Parameters.Add("FocusFilter", OracleDbType.Varchar2).Value = sendSubType; //OracleDataAdapter da = new OracleDataAdapter(cmd0); cmd0.ExecuteNonQuery(); Console.WriteLine(); } //sql = "select * from test_table"; OracleCommand cmd = new OracleCommand(sql, connection); cmd.CommandType = System.Data.CommandType.Text; OracleDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { TrendsObject robj = new TrendsObject(reader.GetString(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(4)); Tmodel.answer.Add(robj); } OracleCommand cmd2 = new OracleCommand("truncate table trends", connection); cmd2.CommandType = System.Data.CommandType.Text; cmd2.ExecuteNonQuery(); connection.Close(); } //ViewBag.NbColumns = columns; //ViewBag.Tlist = tempList; //ViewBag.Class_Type = class_type; return(Json(Tmodel.answer, JsonRequestBehavior.AllowGet)); //return View("loadTrends", new Tuple<TrendsModel, Discipline>(Tmodel, null)); }
public JsonResult GetTrends(string startDate, string endDate) { if (string.IsNullOrWhiteSpace(startDate)) { startDate = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd"); } if (string.IsNullOrWhiteSpace(endDate)) { endDate = DateTime.Now.ToString("yyyy-MM-dd"); } //todo:返回所有竞品数据 Process p = new Process(); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "baidu/demo.py"); string sArguments = $"{path} {startDate} {endDate}"; p.StartInfo.FileName = m_configuration["Python"]; p.StartInfo.Arguments = sArguments; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); StreamReader sReader = p.StandardOutput; string[] output = sReader.ReadToEnd().Split('\r'); TrendsModel trendsModel = new TrendsModel(); trendsModel.Fooww = JsonConvert.DeserializeObject <List <Trend> >(output[0]); trendsModel.FangYou = JsonConvert.DeserializeObject <List <Trend> >(output[1]); trendsModel.HaoFangTong = JsonConvert.DeserializeObject <List <Trend> >(output[2]); trendsModel.YiFangDaShi = JsonConvert.DeserializeObject <List <Trend> >(output[3]); trendsModel.FangZaiXian = JsonConvert.DeserializeObject <List <Trend> >(output[4]); //trendsModel.FangWangTong = JsonConvert.DeserializeObject<List<Trend>>(output[5]); //todo:返回微信指数 string url = "http://zhishu.sogou.com/getDateData?kwdNamesStr=%E6%A2%B5%E8%AE%AF%E6%88%BF%E5%B1%8B%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F,%E6%88%BF%E5%8F%8B,%E5%A5%BD%E6%88%BF%E9%80%9A,%E6%98%93%E6%88%BF%E5%A4%A7%E5%B8%88,%E6%88%BF%E5%9C%A8%E7%BA%BF" + $"&startDate={startDate.Replace("-", "")}&endDate={endDate.Replace("-", "")}&dataType=SEARCH_ALL&queryType=INPUT"; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; var response = request.GetResponse(); var sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); string retXml = sr.ReadToEnd(); sr.Close(); WeiChatTrendsModel r = JsonConvert.DeserializeObject <WeiChatTrendsModel>(retXml); trendsModel.Fooww.AddRange(r.Data.PvList[0].Select(x => new Trend { Index = x.PV, Date = DateTime.ParseExact(x.Date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) })); trendsModel.FangYou.AddRange(r.Data.PvList[1].Select(x => new Trend { Index = x.PV, Date = DateTime.ParseExact(x.Date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) })); trendsModel.HaoFangTong.AddRange(r.Data.PvList[2].Select(x => new Trend { Index = x.PV, Date = DateTime.ParseExact(x.Date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) })); trendsModel.YiFangDaShi.AddRange(r.Data.PvList[3].Select(x => new Trend { Index = x.PV, Date = DateTime.ParseExact(x.Date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) })); trendsModel.FangZaiXian.AddRange(r.Data.PvList[4].Select(x => new Trend { Index = x.PV, Date = DateTime.ParseExact(x.Date, "yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture) })); trendsModel.Fooww = trendsModel.Fooww.GroupBy(x => new { x.Date }).Select(group => new Trend { Index = group.Sum(g => g.Index), Date = group.Key.Date }).ToList(); trendsModel.FangYou = trendsModel.FangYou.GroupBy(x => new { x.Date }).Select(group => new Trend { Index = group.Sum(g => g.Index), Date = group.Key.Date }).ToList(); trendsModel.HaoFangTong = trendsModel.HaoFangTong.GroupBy(x => new { x.Date }).Select(group => new Trend { Index = group.Sum(g => g.Index), Date = group.Key.Date }).ToList(); trendsModel.YiFangDaShi = trendsModel.YiFangDaShi.GroupBy(x => new { x.Date }).Select(group => new Trend { Index = group.Sum(g => g.Index), Date = group.Key.Date }).ToList(); trendsModel.FangZaiXian = trendsModel.FangZaiXian.GroupBy(x => new { x.Date }).Select(group => new Trend { Index = group.Sum(g => g.Index), Date = group.Key.Date }).ToList(); List <List <string[]> > model = new List <List <string[]> >(); model.Add(trendsModel.Fooww.Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); model.Add(trendsModel.FangYou.Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); model.Add(trendsModel.HaoFangTong.Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); model.Add(trendsModel.YiFangDaShi.Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); model.Add(trendsModel.FangZaiXian.Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); //List<List<string[]>> model = new List<List<string[]>>(); //model.Add(JsonConvert.DeserializeObject<List<Trend>>(output[0]).Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); //model.Add(JsonConvert.DeserializeObject<List<Trend>>(output[1]).Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); //model.Add(JsonConvert.DeserializeObject<List<Trend>>(output[2]).Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); //model.Add(JsonConvert.DeserializeObject<List<Trend>>(output[3]).Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); //model.Add(JsonConvert.DeserializeObject<List<Trend>>(output[4]).Select(a => new string[] { a.Date.ToString("yyyy-MM-dd"), a.Index.ToString() }).ToList()); return(Json(model)); }