Example #1
0
        public JsonResult GetAllMeasurementOnStation(string station) //Have to be changed so it get parsed in the string for connection
        {
            IMongoCollection <Measurement> collection = conn.ConnectToMeasurement("Trafik_DB", "Measurements");
            var filt = Builders <Measurement> .Filter.Text(station);

            return(Json(collection.Find(filt).ToList()));
        }
Example #2
0
        public JsonResult GetCarTypes(DateTime from, DateTime to, int areacode) //Have to be changed so it get parsed in the string for connection
        {
            IMongoCollection <Measurement> collection = conn.ConnectToMeasurement("Trafik_DB", "Measurements");
            var filt = Builders <Measurement> .Filter.Where(x => x.areaCode == areacode) & Builders <Measurement> .Filter.Where(x => x.dateTime > from.ToUniversalTime() && x.dateTime < to.ToUniversalTime());

            /*
             * Should add a filter to sort and count the number of each type of car
             * so it is the DB and not the script that has to do the work
             * and so we don't have to return the objects, but just the amount of each match
             */
            var result = collection.Find(filt).ToList();

            Dictionary <int, int> types = new Dictionary <int, int>();

            //List<int> types = new List<int>();

            foreach (var item in result)
            {
                if (types.ContainsKey(item.carType) == false)
                {
                    types.Add(item.carType, 0);
                }
                types[item.carType]++;
            }

            int[] sorted = new int[types.Count];
            foreach (var item in types)
            {
                sorted[item.Key] = item.Value;
            }

            return(Json(sorted));
        }
        // GET: http://localhost:57719/api/MeasurementCount/GetMeasurements?from=2017-08-14%2002:00:00&to=2017-09-15%2002:00:00&stationid=46102360
        // GET: http://adm-trafik-01.odknet.dk:2008/api/MeasurementCount/GetMeasurements?from=2017-08-14%2009:50:40&to=2017-09-15&stationid=46102360
        public JsonResult GetMeasurements(DateTime from, DateTime to, int stationid)
        {
            IMongoCollection <Measurement> collection = conn.ConnectToMeasurement("Trafik_DB", "LiveMeasurements");
            var filt = Builders <Measurement> .Filter.Where(x => x.stationid == stationid) & Builders <Measurement> .Filter.Where(x => x.datetime >= from.ToUniversalTime() && x.datetime <= to.ToUniversalTime());

            var CountResult = collection.Find(filt).Count();

            return(Json(CountResult));
        }
Example #4
0
        public void InsertMeasurement(DateTime dateTime, string lane, string speed, string length, string type, string gap, string wrongDir, string display, string flash, string stationName)
        {
            IMongoCollection <Measurement> collection = conn.ConnectToMeasurement("Trafik_DB", "Measurements");

            collection.InsertOne(new Measurement(dateTime, int.Parse(lane), int.Parse(speed), int.Parse(length), int.Parse(type), int.Parse(gap), int.Parse(wrongDir), int.Parse(display), int.Parse(flash), stationName));
        }