Example #1
0
        public static void rewriteEventList(
            int userId,
            string csvFile)
        {
            //remove all existing annotations
            Annotation_Rep.RmAllAnnotations(userId);

            //This method rewrites the whole list of events
            SQLiteConnection con     = new SQLiteConnection(DbString);
            SQLiteCommand    command = new SQLiteCommand(con);

            con.Open();

            //first, for each day, merge all events into one (1st event)
            DateTime[] dayList = calendar_control.get_list_of_available_days_for_user(userId);
            for (int d = 0; d < dayList.Length; d++)
            {
                //get events in day
                DateTime         day       = dayList[d];
                List <Event_Rep> dayEvents = GetDayEvents(userId, day, false);
                int firstEventId           = dayEvents[0].eventID;
                //set id of events 2:n to firstEventId
                for (int e = 1; e < dayEvents.Count; e++)
                {
                    int currentEvent = dayEvents[e].eventID;
                    command.CommandText =
                        Database_Versioning.text_for_stored_procedures.spUpdate_image_sensors_tables_with_new_event_id_after_target_time(
                            userId, firstEventId, currentEvent, day);
                    command.ExecuteNonQuery();
                    //now delete existing event id
                    DeleteEvent(userId, currentEvent);
                }
                //update db event info (i.e. new start/end times, num images, etc.)
                UpdateDBEventInfo(userId, firstEventId);

                //there should only be 1 event for this day...
                Event_Rep firstEvent = Event_Rep.GetDayEvents(userId, day, false)[0];

                //read list of boundary times from csv (i.e. episode start times)
                List <DateTime> boundaryList   = new List <DateTime>();
                List <string>   annotationList = new List <string>();
                Daily_Annotation_Summary.getBoundInfoFromCsv(csvFile, firstEvent.startTime, firstEvent.endTime, ref boundaryList, ref annotationList);

                //split into multiple events based on list of boundary times
                Event_Rep.SplitMultipleEvents(userId, firstEvent.eventID, boundaryList, annotationList);
            }
            con.Close();
        } //close method split_event_into_two()...