public List <AccidentText> GetRailAccidentText()
    {
        List <AccidentText> res = new List <AccidentText>();

        operation.InitConnection(data_resource);
        string           sql    = "select * from accident_text order by accident_text_id asc";
        SqliteDataReader reader = operation.ExecuteQuery(sql);

        while (reader.Read())
        {
            AccidentText t = new AccidentText();
            t.title       = reader.GetString(reader.GetOrdinal("accident_title"));
            t.description = reader.GetString(reader.GetOrdinal("accident_description"));
            string       type          = reader.GetString(reader.GetOrdinal("accident_type"));
            AccidentType accident_type = AccidentType.rail;

            if (type == "Airport")
            {
                accident_type = AccidentType.airport;
            }
            t.type = accident_type;
            res.Add(t);
        }
        operation.CloseConnection();
        return(res);
    }
 public AccidentTypeDto Map(AccidentType entity)
 {
     return new AccidentTypeDto
                {
                    Id = entity.Id,
                    Description = entity.Description
                };
 }
Пример #3
0
    public void CreateAccident(AccidentType type, int location, int duration, DateTime starttime, int text)
    {
        Accident accident = new Accident
        {
            duration  = duration,
            location  = location,
            starttime = starttime,
            type      = type,
            text      = accidentTexts[text]
        };

        Debug.Log(accident.starttime);
        accident = stringProcess.AccidentStringProcess(accident);
        PushAccident(accident);
        CreateAccidentWarning(accident);
    }
    public List <int> DelayTickets(DateTime accident_happen_time, int city_id, int duration, AccidentType type)
    {
        List <int> affected_routine_ids = new List <int>();

        if (type == AccidentType.rail)
        {
            CityMapping nodes      = CityUtil.Instance.GetEdgeCity(city_id);
            string      start_node = nodes.start_node;
            string      end_node   = nodes.end_node;

            try
            {
                operation.InitConnection(data_resource);
                string sql = "select * from routine where ((start_node like \"%" + start_node + "%\"" + " and end_node like \"%" + end_node + "%\""
                             + ") or  " + "(start_node like \"%" + end_node + "%\"" + " and end_node like \"%" + start_node + "%\")"
                             + " ) and type = 0 order by start_time";

                Lucky.LuckyUtils.Log("select all the start node sql " + sql);

                SqliteDataReader reader = operation.ExecuteQuery(sql);
                List <Routine>   res    = RoutineOperation.GetRoutinInfo(reader);
                operation.CloseConnection();
                Lucky.LuckyUtils.Log("res result " + res.Count);

                List <Routine> delay_routine = new List <Routine>();
                UInt64         accident_happen_time_seconds = RoutineOperation.GetSeconds(accident_happen_time);
                //Lucky.LuckyUtils.Log("accident_happen_time_seconds " + accident_happen_time_seconds);
                //Lucky.LuckyUtils.Log("accident_happen_time_seconds " + accident_happen_time_seconds);


                foreach (Routine t in res)
                {
                    UInt64 begin_time = RoutineOperation.GetSeconds(t.GetBeginTime());
                    //Lucky.LuckyUtils.Log("begin time " + begin_time);

                    UInt64 end_time = RoutineOperation.GetSeconds(t.GetEndTime());

                    if (begin_time >= accident_happen_time_seconds)
                    {
                        int routine_id = t.GetRoutineId();
                        //Lucky.LuckyUtils.Log("lucky routine_id "+ routine_id);
                        UInt64 actual_begin_time = begin_time + (UInt32)duration * 60;
                        UInt64 actual_end_time   = end_time + (UInt32)duration * 60;

                        sql = "update routine set actual_start_time = " + actual_begin_time + ", actual_end_time = " + actual_end_time + ", event_happen_time = " + accident_happen_time_seconds
                              + " where routine_id = " + routine_id;

                        operation.InitConnection(data_resource);
                        reader = operation.ExecuteQuery(sql);//

                        if (reader.RecordsAffected == 1)
                        {
                            affected_routine_ids.Add(routine_id);
                            operation.CloseConnection();
                        }
                    }
                }
            }
            finally
            {
                operation.CloseConnection();
            }
            return(affected_routine_ids);
        }

        if (type == AccidentType.airport)
        {
            string city_name = CityUtil.Instance.GetCityName(city_id);
            Lucky.LuckyUtils.Log("city name " + city_name);

            try
            {
                operation.InitConnection(data_resource);
                string sql = "select * from routine where (start_node like \"%" + city_name + "%\"  or end_node like \"%" + city_name + "%\")" + " and type = 1 order by start_time";

                Lucky.LuckyUtils.Log("select all the start node sql " + sql);

                SqliteDataReader reader = operation.ExecuteQuery(sql);
                List <Routine>   res    = RoutineOperation.GetRoutinInfo(reader);
                operation.CloseConnection();
                Lucky.LuckyUtils.Log("res result " + res.Count);

                List <Routine> delay_routine = new List <Routine>();
                UInt64         accident_happen_time_seconds = RoutineOperation.GetSeconds(accident_happen_time);
                Lucky.LuckyUtils.Log("accident_happen_time_seconds " + accident_happen_time_seconds);


                foreach (Routine t in res)
                {
                    UInt64 begin_time = RoutineOperation.GetSeconds(t.GetBeginTime());

                    UInt64 end_time = RoutineOperation.GetSeconds(t.GetEndTime());

                    if (begin_time >= accident_happen_time_seconds)
                    {
                        int    routine_id        = t.GetRoutineId();
                        UInt64 actual_begin_time = begin_time + (UInt32)duration * 60;
                        UInt64 actual_end_time   = end_time + (UInt32)duration * 60;

                        sql = "update routine set actual_start_time = " + actual_begin_time + ", actual_end_time = " + actual_end_time + ", event_happen_time = " + accident_happen_time_seconds
                              + " where routine_id = " + routine_id;

                        operation.InitConnection(data_resource);
                        reader = operation.ExecuteQuery(sql);//

                        if (reader.RecordsAffected == 1)
                        {
                            affected_routine_ids.Add(routine_id);
                            operation.CloseConnection();
                        }
                    }
                }
            }
            finally
            {
                operation.CloseConnection();
            }
            return(affected_routine_ids);
        }
        return(affected_routine_ids);
    }