コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        protected MoodleEvent getEventObject(MySqlDataReader reader)
        {
            MoodleEvent mooEvent;

            mooEvent = new MoodleEvent(int.Parse(reader["id"].ToString()), int.Parse(reader["userid"].ToString()), int.Parse(reader["courseid"].ToString()), reader["action"].ToString(), Database.fromUnix(Convert.ToInt64(reader["timecreated"])));
            return(mooEvent);
        }
コード例 #2
0
        /// <summary>
        /// Updates the location DB taking all of the items
        /// from week and adding them to the week
        /// </summary>
        private void updateWeek()
        {
            ///Get and Sort Events.
            DateTime           date         = DateTime.Now;
            List <MoodleEvent> todaysEvents = MoodleDB.getMoodleDB().getDaysEvents(); //Change

            todaysEvents = System.getSystem().sortEventsList(todaysEvents);

            List <MoodleEvent> userEvents = new List <MoodleEvent>();

            //Fixes Issue with foreach.
            MoodleEvent e = new MoodleEvent(0, 0, 0, "", DateTime.Now);

            todaysEvents.Add(e);
            int currentID = -1;

            foreach (MoodleEvent evt in todaysEvents)
            {
                if (currentID == evt.userID) //Sane user.
                {
                    userEvents.Add(evt);
                }
                //Current event has diffrent user than the current list.
                //so counts the current list, add to database then deals with
                //current event.
                else if (currentID != evt.userID && userEvents.Count > 0)
                {
                    int countOff = 0;
                    int countOn  = 0;
                    Dictionary <MoodleCourse, List <int> > courseAvgs = new Dictionary <MoodleCourse, List <int> >();
                    //Get user locations
                    List <LocationEvent> Locations = LocationDB.getLocationDB().getUserLocation(evt.userID);
                    foreach (MoodleEvent userEvt in userEvents)
                    {
                        //Compare events and location
                        foreach (MoodleEvent moodleEvt in userEvents) //Events
                        {
                            bool found = false;
                            foreach (LocationEvent loc in Locations) //Locations
                            {
                                //Check Time within 10 mins
                                DateTime timeplus = new DateTime();
                                timeplus = loc.time;
                                timeplus.AddMinutes(10);
                                if (Math.Abs((moodleEvt.time - loc.time).TotalMinutes) <= 10 && Math.Abs((moodleEvt.time - loc.time).TotalMinutes) >= 0)
                                {
                                    //Find if on campus
                                    foreach (Campus c in System.getSystem().campus)
                                    {
                                        if (c.isIn(loc.lat, loc.lng)) //Check Location
                                        {
                                            countOn++;
                                            found = true;
                                            bool foundCourse = false;


                                            MoodleCourse mc = null;
                                            foreach (MoodleCourse course in courseAvgs.Keys)
                                            {
                                                if (course.ID == moodleEvt.courseID)
                                                {
                                                    foundCourse = true;
                                                    mc          = course;
                                                    break;
                                                }
                                            }
                                            //Update
                                            if (foundCourse)
                                            {
                                                List <int> list = courseAvgs[mc];
                                                list[0]        = list[0]++;
                                                courseAvgs[mc] = list;
                                                mc             = null;
                                            }
                                            else //Add Course
                                            {
                                                List <int> list = new List <int>();
                                                list.Add(1);
                                                list.Add(0);
                                                if (moodleEvt.courseID > 0)
                                                {
                                                    mc = MoodleDB.getMoodleDB().getCourse(moodleEvt.courseID);
                                                    if (mc != null)
                                                    {
                                                        courseAvgs.Add(mc, list);
                                                    }
                                                    mc = null;
                                                }
                                            }
                                        }
                                    }
                                    if (!found)
                                    {
                                        countOff++;
                                        bool         foundCourse = false;
                                        MoodleCourse mc          = null;
                                        foreach (MoodleCourse course in courseAvgs.Keys)
                                        {
                                            if (course.ID == moodleEvt.courseID)
                                            {
                                                mc          = course;
                                                foundCourse = true;
                                            }
                                        }
                                        if (evt.courseID > 0)
                                        {
                                            //Update
                                            if (foundCourse)
                                            {
                                                List <int> list = courseAvgs[mc];
                                                list[1]        = list[1]++;
                                                courseAvgs[mc] = list;
                                                mc             = null;
                                            }
                                            else //course not in list
                                            {
                                                List <int> list = new List <int>();
                                                list.Add(0);
                                                list.Add(1);
                                                courseAvgs.Add(MoodleDB.getMoodleDB().getCourse(moodleEvt.courseID), list);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //get time at campus
                    int timeOn  = countOn * 10;
                    int timeOff = countOff * 10;

                    //Add to Database.
                    //Generic.
                    LocationDB.getLocationDB().addLocationWeekEvents(currentID, timeOn, timeOff);
                    //Per Course.
                    foreach (MoodleCourse course in courseAvgs.Keys)
                    {
                        List <int> list = courseAvgs[course];
                        int        on   = list[0] * 10;
                        int        off  = list[1] * 10;
                        //Add to DB.
                        LocationDB.getLocationDB().addLocationWeekEventsCourse(currentID, course.ID, on, off);
                    }
                    userEvents = new List <MoodleEvent>();
                } // End Final
                else if (currentID != evt.userID)
                {
                    currentID = evt.userID;
                    userEvents.Add(evt);
                }
            }
        }