Пример #1
0
        public void run()
        {
            init();

            // delete already existing data from database
            db.ExecuteNonQuery("DELETE FROM " + Constants.ExperimentsTable + " WHERE algorithm_id = " + experimentMethodCode + " and population_group = " + experimentGroup);

            // At this stage we have everything we need to run the experiment
            // We should run the experiment on 5 different parameters mentioned in ExperimentInputParams
            var inputParams = new ExperimentInputParams();

            Users = new List <User>(50000);
            for (int i = 0; i < Users.Capacity; i++)
            {
                Users.Add(null);
            }

            foreach (var pop in inputParams.percentOfParticipants)
            {
                foreach (var pou in inputParams.percentOfUpdatesUsed)
                {
                    for (int i = 0; i < Users.Capacity; i++)
                    {
                        Users[i] = null;
                    }
                    UserTags = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    UserTags = (from tag in TotalReportedUserTags where tag.RandomUserValue <= pop && tag.RandomColumnValue <= pou select tag).ToList();
                    var usersids = (from tag in UserTags select new { id = tag.UserID, trust = tag.UserTrust }).Distinct().ToList();
                    for (int i = 0; i < usersids.Count; i++)
                    {
                        Users[usersids[i].id] = new User(usersids[i].id, usersids[i].trust, 50);
                    }

                    foreach (var dc in inputParams.discounted)
                    {
                        foreach (var mt in inputParams.maxTrust)
                        {
                            foreach (var pot in inputParams.percentOfTraining)
                            {
                                var options = new ExperimentOptions(dc, mt, pop, pou, pot, experimentMethodCode, experimentGroup);
                                if (UserTags.Count > 0)
                                {
                                    Method method = new Method(Occupancies, Users, UserTags, options);

                                    MethodPerformance performance = method.Execute();

                                    int experiment_id = storeExperiment2db(performance, options);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        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);
            }
        }