Ejemplo n.º 1
0
        public ContentResult getFittedModelHourlyTable(string Type = "SUM", int idDistrict = 62, string weatherDependency = "000000", int startIDDate = 20140101, int endIDDate = 20150101)
        {
            WeatherColumns wd = WeatherColumnConversion.stringToWeatherColumn(weatherDependency);

            ModelType modelTp = (ModelType)Enum.Parse(
                typeof(ModelType), Type, true);

            switch (modelTp)
            {
            case ModelType.AVERAGE:
            {
                am.modelChange(getHourlyModelTable(Type, idDistrict, startIDDate, endIDDate).Content, MODEL_FITTED, wd);
                var returnValue = am.fitSeriesToModel(getHourlyPlaceTable(1622, startIDDate, endIDDate).Content, MODEL_FITTED, "HourlyDataPlace", wd);

                return(new ContentResult {
                        Content = returnValue.ToJSON(), ContentType = "application/json"
                    });
            }
            break;

            case ModelType.SUM:
            {
                am.modelChange(getHourlyModelTable(Type, idDistrict, startIDDate, endIDDate).Content, MODEL_FITTED, wd);
                var returnValue = am.fitSeriesToModel(getHourlyPlaceTable(1622, startIDDate, endIDDate).Content, MODEL_FITTED, "HourlyDataPlace", wd);

                return(new ContentResult {
                        Content = returnValue.ToJSON(), ContentType = "application/json"
                    });
            }
            break;

            default:
                throw new Exception("Bad type");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the forecast.
        /// </summary>
        /// <param name="Type">The type.</param>
        /// <param name="weatherDependency">The weather dependency.</param>
        /// <param name="IDConsuptionPlace">The identifier consuption place.</param>
        /// <param name="lenght">The lenght.</param>
        /// <param name="startIDDate">The start identifier date.</param>
        /// <returns></returns>
        public ContentResult getForecast(string Type = "SUM", string weatherDependency = "000000", long IDConsuptionPlace = 1622, int lenght = 5, int startIDDate = 20141210)
        {
            //const string MODEL_FIT = "model_fit";
            const string MODEL_FITTED_SHORTER = "model_fit_short";
            const string DATA_SHORT           = "data_short";

            weatherDependency = "000000";
            WeatherColumns wd = WeatherColumnConversion.stringToWeatherColumn(weatherDependency);
            //WeatherColumns wd = WeatherColumnConversion.stringToWeatherColumn(weatherDependency);

            //string modelJson = getDailyModelTable(Type, endIDDate: startIDDate).Content; // start date of forcast is end date of series
            //am.modelChange(modelJson, MODEL_FIT, wd);

            //string placeJson = getDailyPlaceTable(IDConsuptionPlace, endIDDate: startIDDate).Content;

            //am.fitSeriesToModel(placeJson, MODEL_FIT, DATA_PLACE, wd);

            var consPlace = db.ConsuptionPlaces
                            .Join(db.PlaceWeathers
                                  , cp => cp.DistrictName, pw => pw.DistrictName, (cp, pw) => new { pw.IDLocation, pw.IDDistrict, cp.IDConsuptionPlace })
                            .Single(cp => cp.IDConsuptionPlace.Equals(IDConsuptionPlace));

            try
            {
                string modelJsonShort = getDailyModelTable("SUM", consPlace.IDDistrict, endIDDate: 20141210).Content;

                am.modelChange(modelJsonShort, MODEL_FITTED_SHORTER, wd);
                string placeJsonShort = getDailyPlaceTable(IDConsuptionPlace, endIDDate: startIDDate).Content;
                am.fitSeriesToModel(placeJsonShort, MODEL_FITTED_SHORTER, DATA_SHORT, wd);

                string        FORECAST_RESULT_VARIABLE = "forecast_result_variable";
                List <double> forecatsList             = am.makeForecast(DATA_SHORT, getWeather(consPlace.IDLocation, startIDDate, startIDDate + 4).Content, lenght, FORECAST_RESULT_VARIABLE);
                //measured values
                string measuredValues = getDailyPlaceTable(consPlace.IDConsuptionPlace, startIDDate, startIDDate + lenght).Content;

                Forecast f = new Forecast();
                f.Means     = forecatsList;
                f.Accuracy  = am.compareResults(measuredValues, FORECAST_RESULT_VARIABLE);
                f.Residuals = forecatsList;
                log.Info(string.Format("cp:{0}\tidDistrict:{1}\ttype:{3}\tweather:{4}\taccuracy:{2}", IDConsuptionPlace, consPlace.IDDistrict, f.Accuracy, Type, weatherDependency));
                return(new ContentResult {
                    Content = forecatsList.ToJSON(), ContentType = "application/json"
                });
            }
            catch (Exception EX_NAME)
            {
                log.Info(string.Format("cp:{0}\tidDistrict:{1}\ttype:{3}\tweather:{4}\taccuracy:Error", IDConsuptionPlace, consPlace.IDDistrict, "", Type, weatherDependency));
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the biggest outliers.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="weatherDependency">The weather dependency.</param>
        /// <param name="IDConsuptionPlace">The identifier consuption place.</param>
        /// <returns></returns>
        public ActionResult getBiggestOutliers(string model = "SUM", string weatherDependency = "000000", int IDConsuptionPlace = 1622)
        {
            const string MODEL_FIT  = "model_fit";
            const string DATA_PLACE = "data_place";

            WeatherColumns wd = WeatherColumnConversion.stringToWeatherColumn(weatherDependency);

            string modelJson = getDailyModelTable(model).Content;

            am.modelChange(modelJson, MODEL_FIT, wd);
            string placeJson = getDailyPlaceTable(IDConsuptionPlace).Content;

            am.fitSeriesToModel(placeJson, MODEL_FIT, DATA_PLACE, wd);
            List <Outlier> outliers = new List <Outlier>();

            //WeatherColumns nonerue = new WeatherColumns(new byte[] { 0, 0, 0, 0, 1, 1 });
            outliers = am.findOutliers(DATA_PLACE, wd);
            outliers = am.FindLocalProperties(placeJson, modelJson, wd, outliers);
            //outliersList = outliers.OrderBy(o => o.outlierness.Max());
            Outlier emptyOutlier = new Outlier()
            {
                IDDate = 20130101, outlierness = new List <double>(4), seriesNumber = -1, tStats = new List <double>(4)
            };

            for (int i = 0; i < 8; i++)
            {
                emptyOutlier.outlierness.Add(0);
                emptyOutlier.tStats.Add(0);
            }
            foreach (Outlier ou in outliers)
            {
                log.Info(ou.seriesNumber + " :" + ou.outlierness[0]);
            }
            outliers.Insert(0, emptyOutlier);
            return(new ContentResult {
                Content = outliers.ToJSON(), ContentType = "application/json"
            });
        }