public KparkFuser(List <DatabaseOccuapncyUpdateAction> Actions, SimOptions Options, Dictionary <int, List <double> > TrustUpdates) { actions = Actions; options = Options; this.TrustUpdates = TrustUpdates; db = new Dissertation.SqlServerConnector(); entireUpdates = GetEntireUpdatesFromLocalDatabase(); const int nSections = 6; Sections = new SectionInformation[nSections]; for (int i = 0; i < nSections; i++) { Sections[i] = new SectionInformation() { LastUpdated = new DateTime(1000, 1, 1), Occupancy = -1 } } ; Users = new User[50000]; for (int i = 0; i < Users.Length; i++) { Users[i] = new User() { Trust = 0.99, Score = 0.5 } } ; }
public void TransferDataFromKparkServerToLocalMsSql() { var serverDb = new MySqlConnector(); var localDb = new Dissertation.SqlServerConnector(); string query; localDb.ExecuteNonQuery("truncate table realUserUpdates"); //query = "SELECT * FROM entries WHERE uid not in (1,44)"; query = "SELECT entries.uid,entries.sid,entries.datetime,sectionnumber,occupancy FROM entries JOIN sections2 on entries.sid=sections2.sid JOIN parkings on parkings.pid=sections2.pid WHERE uid not in (1,44) and datetime>'2014-9-17'"; // and parkings.pid = 21 and floor=1 var RealDataEntries = serverDb.ExecuteSelect(query); // get section real tags query = "SELECT dbo.cardata.id, dbo.cardata.occupancy, dbo.cardata.day, dbo.cardata.weekday, dbo.cardata.hour, dbo.sectionProbabilities.section_id, dbo.sectionProbabilities.hour_id, dbo.sectionProbabilities.prob FROM dbo.cardata INNER JOIN dbo.sectionProbabilities ON dbo.cardata.id = dbo.sectionProbabilities.hour_id"; var result2 = localDb.ExecuteQuery(query); Dictionary <string, int> HourSectionTagHash = HashHourSections(result2); Random random = new Random(); string uid, sectionNumber, tag, day, hour, weekday, realtag; DateTime timeOfTag; TimeSpan span; localDb.ExecuteNonQuery("truncate table realUserUpdates"); localDb.ExecuteNonQuery("truncate table realExperiments"); for (int i = 0; i < RealDataEntries["uid"].Count; i++) { timeOfTag = DateTime.Parse(RealDataEntries["datetime"][i]); span = timeOfTag - DateTime.Parse("9/15/2014"); // first Monday before the experiment started (day 0 is monday) span = span.Add(new TimeSpan(2, 0, 0)); // colorado time difference day = span.Days.ToString(); weekday = determinWeekDay(timeOfTag.DayOfWeek.ToString()).ToString(); hour = span.Hours.ToString(); sectionNumber = RealDataEntries["sectionnumber"][i]; realtag = HourSectionTagHash[day + "_" + weekday + "_" + hour + "_" + sectionNumber].ToString(); query = string.Format("INSERT INTO [dbo].[realUserUpdates] ([usergroup] ,[uid] ,[user_section] ,[real_section] ,[user_tag] ,[real_tag] ,[user_trust] ,[day] ,[weekday] ,[hour] ,[randcol] ,[randusercol], [date_received]) VALUES ({0} ,{1} ,{2} ,{3} ,{4} ,{5} ,{6} ,{7} ,{8} ,{9} ,{10} ,{11}, '{12}')", 0, RealDataEntries["uid"][i], sectionNumber, RealDataEntries["sectionnumber"][i], RealDataEntries["occupancy"][i], realtag, 50, day, weekday, hour, random.NextDouble(), random.NextDouble(), RealDataEntries["datetime"][i]); localDb.ExecuteNonQuery(query); } }