static public void ReCalcForecastItems()
        {
            forecastItems.Clear();

            foreach (ProductMasterItem productMasterItem in _productMasterList)
            {
                ForecastItem newForecastItem = new ForecastItem();
                newForecastItem.ProductCode        = productMasterItem.ProductionCode;
                newForecastItem.ProductDescription = productMasterItem.Description;

                double inventory =
                    InventoryItems.Where(x => x.ProductCode == productMasterItem.ProductionCode).Sum(x => x.Units);

                for (Int32 i = 0; i < newForecastItem.UnitsPerMonth.Length; i++)
                {
                    SalesItem[] foundItems = SalesItems.Where(x => x.MasterID == productMasterItem.MasterID &&
                                                              x.Date.Month == DateTime.Now.AddMonths(-(i + 1)).Month&& x.Date.AddYears(1).AddMonths(1) >= DateTime.Now).ToArray();

                    newForecastItem.UnitsPerMonth[i] = foundItems.Sum(x => (x.Units / productMasterItem.PiecesPerUnit));
                }

                newForecastItem.Units = inventory;

                forecastItems.Add(newForecastItem);
            }
        }
Пример #2
0
        private List <ForecastItem> createExampleForecast(DateTime time)
        {
            string[]            ps      = new string[] { "PM2.5", "PM10", "SO2", "O3", "CO", "NO2" };
            List <ForecastItem> result  = new List <ForecastItem>();
            DateTime            endTime = time.AddDays(3);
            Random r = new Random();

            while (time <= endTime)
            {
                ForecastItem item = new ForecastItem();
                if (time.Hour >= 6 && time.Hour <= 18)
                {
                    item.Time = time.Day + "日白天";
                }
                else
                {
                    item.Time = time.Day + "日夜间";
                }
                item.Aqi = r.Next(1, 300);
                var g = _aqiGradeService.CalcGrade(item.Aqi);
                item.AqiLevel         = g.Grade.ToString();
                item.PrimaryParameter = ps[r.Next(0, 6)];
                result.Add(item);
                time = time.AddHours(12);
            }
            return(result);
        }
Пример #3
0
        public async Task <ForecastItem> getForecast()
        {
            var          service  = RestService.For <weatherInt>("https://api.forecast.io/forecast");
            ForecastItem forecast = new ForecastItem();
            ForecastItem task     = await service.getForecast("63f0914cdd082e76d25b40161cbe70c4", "53.347", "6.2597");

            return(task);
        }
Пример #4
0
 private void RemoveItem(ForecastItem item)
 {
     Items.Remove(item);
     if (item.Pinned)
     {
         item.UnPin();
     }
 }
Пример #5
0
        public static void EvaluateFeed(string feed, Dictionary <string, string> weatherFontMapping, Forecast forecast)
        {
            forecast.Forecasts.Clear();
            var f = JsonConvert.DeserializeObject <Models.Forecast.RootObject>(feed);

            forecast.City = f.city.name;
            if (!string.IsNullOrEmpty(f.city.country))
            {
                forecast.City += " (" + f.city.country + ")";
            }
            foreach (var entry in f.list)
            {
                var item = new ForecastItem {
                    Date = ConvertFromUnixTimestamp(entry.dt)
                };

                if (entry.main != null)
                {
                    item.HumidityPercentage = entry.main.humidity;
                    item.PressurehPa        = entry.main.pressure;
                    item.TemperatureKelvin  = entry.main.temp;
                }

                if (entry.weather != null && entry.weather.Any())
                {
                    var weather = entry.weather.FirstOrDefault();
                    item.ConditionId = weather.id;
                    if (weatherFontMapping.ContainsKey(weather.id.ToString()))
                    {
                        item.ConditionFontIcon = ((char)int.Parse(weatherFontMapping[weather.id.ToString()], System.Globalization.NumberStyles.HexNumber)).ToString();
                    }
                    item.Description = weather.description;
                }

                if (entry.clouds != null)
                {
                    item.CloudinessPercentage = entry.clouds.all;
                }

                if (entry.wind != null)
                {
                    item.WindDegreee = entry.wind.deg;
                    item.WindSpeed   = entry.wind.speed;
                }

                if (entry.rain != null)
                {
                    item.RainVolume = entry.rain._3h;
                }

                if (entry.snow != null)
                {
                    item.RainVolume = entry.snow._3h;
                }

                forecast.Forecasts.Add(item);
            }
        }
        // Create new views (invoked by the layout manager)
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            // create a new view
            ForecastItem v = new ForecastItem(parent.Context);

#if __ANDROID_WEAR__
            // set the view's size, margins, paddings and layout parameters
            v.LayoutParameters = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
            int paddingHoriz = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 16, parent.Context.Resources.DisplayMetrics);
            v.SetPaddingRelative(paddingHoriz, 0, paddingHoriz, 0);
#endif
            return(new ViewHolder(v));
        }
Пример #7
0
        public async void GetWeather()
        {
            ForecastItem forcast = await weathermodel.getForecast();

            Daily            dailydata = forcast.daily;
            List <DailyData> data      = dailydata.data;

            if (data.Count > 0)
            {
                mainview.updateForecasts(data);
            }
            else
            {
                mainview.showError();
            }

            mainview.hideProgbar();
        }
Пример #8
0
        private ForecastItem GetForecastItemRowData(Entity forecastCollectionItem, Guid forecastPeriodTypeId, string[] periods,
                                                    string dimensionEntitySchemaName)
        {
            Guid         forecastItemId = GetEntityPrimaryColumnValue(forecastCollectionItem);
            Guid?        parentId       = (Guid?)forecastCollectionItem.GetColumnValue("ParentId");
            string       columnName     = string.Concat(dimensionEntitySchemaName, "_Id_DimensionValueId_Name");
            ForecastItem forecastItem   = new ForecastItem()
            {
                Id                 = forecastItemId,
                Name               = (string)forecastCollectionItem.GetColumnValue(columnName),
                ParentId           = parentId,
                DimensionValueId   = (Guid)forecastCollectionItem.GetColumnValue("DimensionValueId"),
                CanEdit            = false,
                ForecastItemValues = null
            };

            forecastItem.CanEdit = CheckForecastItemRights(forecastItemId, SchemaRecordRightLevels.CanEdit);
            EntityCollection forecastItemValueCollection = GetForecastItemValueCollection(forecastItemId, forecastPeriodTypeId, periods);

            forecastItem.ForecastItemValues = GetForecastItemValuesFullData(forecastItemId, periods,
                                                                            forecastPeriodTypeId, forecastItemValueCollection);
            return(forecastItem);
        }
        public static void AddPastSale(int master, DateTime duedate, double pieces)
        {
            if (duedate.Year == DateTime.Today.Year && duedate.Month == DateTime.Today.Month)
            {
                return;                                                                               //discard current month data
            }
            ForecastItem item = ForecastItems.FirstOrDefault(i => master != -1 && i.MasterID == master);

            var inv        = InventoryItems.FirstOrDefault(x => x.MasterID == master);
            var masterItem =
                ProductMasterList.FirstOrDefault(x => x.MasterID == master);

            if (masterItem != null)
            {
                double units = pieces / masterItem.PiecesPerUnit;

                if (item != null) // if tracking item already
                {
                    item.AddSale(duedate, units);
                }
                else // add tracking
                {
                    double invUnits = 0;
                    if (inv != null)
                    {
                        invUnits = inv.Units;
                    }
                    else
                    {
                        //MessageBox.Show(String.Format("No inventory for id:{0} master {1}", master, masterItem));
                    }
                    item = new ForecastItem(invUnits, masterItem);
                    item.AddSale(duedate, units);
                    ForecastItems.Add(item);
                }
            }
        }
Пример #10
0
        public static WeatherData From(ForecastItem forecast)
        {
            var result = new WeatherData
            {
                Date = forecast.Date.Date, Temperature = forecast.TemperatureInfo.MaxTemperature
            };

            switch (forecast.WeatherInfos.FirstOrDefault()?.Id ?? 0)
            {
            case int n when(n >= 200 && n <= 232):
                result.Condition = WeatherCondition.Thunderstorm;

                break;

            case int n when(n >= 500 && n <= 531):
                result.Condition = WeatherCondition.Drizzle;

                break;

            case int n when(n >= 600 && n <= 622):
                result.Condition = WeatherCondition.Snow;

                break;

            case int n when(n == 800):
                result.Condition = WeatherCondition.Clear;

                break;

            case int n when(n >= 801 && n <= 804):
                result.Condition = WeatherCondition.Clouds;

                break;
            }
            return(result);
        }
        public bool ConvertForecastToExcel()
        {
            GridView    myList = ProductListView.View as GridView;
            Application oXL;
            _Workbook   oWB;
            _Worksheet  oSheet;
            Range       oRng;

            //ProgressDialog.Current.ReportWithCancellationCheck(0, "Loading column headers", 0);

            try
            {
                //Start Excel and get Application object.
                oXL             = new Application();
                oXL.Visible     = true;
                oXL.UserControl = false;

                //Get a new workbook.
                oWB    = oXL.Workbooks.Add(Missing.Value);
                oSheet = (_Worksheet)oWB.ActiveSheet;

                Int32 forecastCount = StaticInventoryTracker.ForecastItems.Count;
                Int32 columnCount   = myList.Columns.Count;
                // Create Int32 array for the location of the headers.
                // [0] is prodcode and stores the index of the header for prodcode, [1] is for description and so on
                Int32 [] ordinals = new int[columnCount];
                //prodCode,prodDesc,units,oneMonthAvg,threeMonth,sixMonth,yearAvg,pastYearAvg,sold1Mo,sold2Mo,sold3Mo,sold4Mo,sold5Mo,sold6Mo,sold7Mo,sold8Mo,sold9Mo,sold10Mo,sold11Mo,sold12Mo,sold13Mo;
                String headerContent;
                //Add table headers going cell by cell.
                for (Int32 index = 0; index < columnCount; index++)
                {
                    GridViewColumn column = myList.Columns[index];
                    headerContent = ((GridViewColumnHeader)column.Header).Content.ToString();
                    char loc = (char)('A' + index);

                    oSheet.Cells[1, index + 1] = headerContent;
                    oSheet.get_Range(String.Format("{0}1", loc)).ColumnWidth = column.ActualWidth * .125;

                    if (headerContent == HrProdCode.Content.ToString())
                    {
                        ordinals[index] = 0;
                    }
                    else if (headerContent == HrDesc.Content.ToString())
                    {
                        ordinals[index] = 1;
                    }
                    else if (headerContent == HrInv.Content.ToString())
                    {
                        ordinals[index] = 2;
                    }
                    else if (headerContent == Hr1MoAvg.Content.ToString())
                    {
                        ordinals[index] = 3;
                    }
                    else if (headerContent == Hr3MoAvg.Content.ToString())
                    {
                        ordinals[index] = 4;
                    }
                    else if (headerContent == Hr6MoAvg.Content.ToString())
                    {
                        ordinals[index] = 5;
                    }
                    else if (headerContent == Hr1YrAvg.Content.ToString())
                    {
                        ordinals[index] = 6;
                    }
                    else if (headerContent == HrLyAvg.Content.ToString())
                    {
                        ordinals[index] = 7;
                    }
                    else if (headerContent == Sold1MonthAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 8;
                    }
                    else if (headerContent == Sold2MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 9;
                    }
                    else if (headerContent == Sold3MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 10;
                    }
                    else if (headerContent == Sold4MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 11;
                    }
                    else if (headerContent == Sold5MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 12;
                    }
                    else if (headerContent == Sold6MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 13;
                    }
                    else if (headerContent == Sold7MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 14;
                    }
                    else if (headerContent == Sold8MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 15;
                    }
                    else if (headerContent == Sold9MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 16;
                    }
                    else if (headerContent == Sold10MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 17;
                    }
                    else if (headerContent == Sold11MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 18;
                    }
                    else if (headerContent == Sold12MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 19;
                    }
                    else if (headerContent == Sold13MonthsAgoColumn.Content.ToString())
                    {
                        ordinals[index] = 20;
                    }
                }
                //Format A1:D1 as bold, vertical alignment = center.
                oSheet.get_Range("A1", "U1").Font.Bold         = true;
                oSheet.get_Range("A1", "U1").VerticalAlignment =
                    XlVAlign.xlVAlignCenter;

                //Exit if no rows exist
                if (forecastCount == 0)
                {
                    return(true);
                }

                // Create an array to insert multiple values at once.
                string[,] forecastValues = new string[forecastCount, columnCount];

                DateTime start = DateTime.Now;
                for (Int32 rowIndex = 0; rowIndex < forecastCount; rowIndex++)
                {
                    //ProgressDialog.Current.ReportWithCancellationCheck(rowIndex/forecastCount, "Writing row {0}/{1}", rowIndex,forecastCount);

                    ForecastItem forecastItem = StaticInventoryTracker.ForecastItems[rowIndex];

                    forecastValues[rowIndex, ordinals[0]]  = forecastItem.ProductCode;
                    forecastValues[rowIndex, ordinals[1]]  = forecastItem.ProductDescription;
                    forecastValues[rowIndex, ordinals[2]]  = forecastItem.Units.ToString();
                    forecastValues[rowIndex, ordinals[3]]  = forecastItem.OneMonthAvg;
                    forecastValues[rowIndex, ordinals[4]]  = forecastItem.ThreeMonthAvg;
                    forecastValues[rowIndex, ordinals[5]]  = forecastItem.SixMonthAvg;
                    forecastValues[rowIndex, ordinals[6]]  = forecastItem.TwelveMonthAvg;
                    forecastValues[rowIndex, ordinals[7]]  = forecastItem.PastYearAvg;
                    forecastValues[rowIndex, ordinals[8]]  = forecastItem.SoldOneMonthAgo;
                    forecastValues[rowIndex, ordinals[9]]  = forecastItem.SoldTwoMonthsAgo;
                    forecastValues[rowIndex, ordinals[10]] = forecastItem.SoldThreeMonthsAgo;
                    forecastValues[rowIndex, ordinals[11]] = forecastItem.SoldFourMonthsAgo;
                    forecastValues[rowIndex, ordinals[12]] = forecastItem.SoldFiveMonthsAgo;
                    forecastValues[rowIndex, ordinals[13]] = forecastItem.SoldSixMonthsAgo;
                    forecastValues[rowIndex, ordinals[14]] = forecastItem.SoldSevenMonthsAgo;
                    forecastValues[rowIndex, ordinals[15]] = forecastItem.SoldEightMonthsAgo;
                    forecastValues[rowIndex, ordinals[16]] = forecastItem.SoldNineMonthsAgo;
                    forecastValues[rowIndex, ordinals[17]] = forecastItem.SoldTenMonthsAgo;
                    forecastValues[rowIndex, ordinals[18]] = forecastItem.SoldElevenMonthsAgo;
                    forecastValues[rowIndex, ordinals[19]] = forecastItem.SoldTweleveMonthsAgo;
                    forecastValues[rowIndex, ordinals[20]] = forecastItem.SoldThirteenMonthsAgo;
                }
                oSheet.Range["A2", String.Format("{0}{1}", (char)('A' + columnCount - 1), forecastCount + 1)].Value2 = forecastValues;

                Console.WriteLine(DateTime.Now - start);
                //AutoFit columns A:D.
                oRng = oSheet.get_Range("A1", String.Format("{0}1", (char)('A' + columnCount - 1)));
                oRng.EntireColumn.AutoFit();

                oXL.UserControl = true;
            }
            catch (Exception theException)
            {
                String errorMessage;
                errorMessage = "Error: ";
                errorMessage = String.Concat(errorMessage, theException.Message);
                errorMessage = String.Concat(errorMessage, " Line: ");
                errorMessage = String.Concat(errorMessage, theException.Source);

                MessageBox.Show(errorMessage, "Error");
            }
            return(true);
        }
 public ViewHolder(ForecastItem v)
     : base(v)
 {
     mForecastItem = v;
 }
        public double GetUnitsToMake(ProductMasterItem nextItem, Configuration config)
        {
            double unitsToMake = 0;
            double maxInShift  = 0;

            maxInShift = config.UnitsToMakeInHours(nextItem, (scheduleLine.Shift.Hours(scheduleLine.Date)));

            var    inventory  = StaticInventoryTracker.InventoryItems.FirstOrDefault(inv => inv.MasterID == nextItem.MasterID);
            double currentInv = inventory?.Units ?? 0;

            double max    = double.MaxValue;
            double min    = 0;
            double target = 0;

            if (nextItem.TurnType == "T")
            {
                ForecastItem forecast = StaticInventoryTracker.ForecastItems.FirstOrDefault(forcast => forcast.MasterID == nextItem.MasterID);
                if (forecast != null)
                {
                    avgSold = forecast.GetAvgUnitsSold(GenerationData.SalesOutlookDuration);
                    if (avgSold == 0)
                    {
                        avgSold = 40;                         // do this to prevent infinite looping
                    }
                    target = avgSold * nextItem.TargetSupply; // avg sold * months supply

                    max = avgSold * nextItem.MaxSupply;
                    min = avgSold * nextItem.MinSupply;

                    // if target is too low
                    if (target + currentInv < min)
                    {
                        unitsToMake = min;
                    }
                    // if target is too high
                    else if (target + currentInv > max)
                    {
                        unitsToMake = max;
                    }
                    // if target is acceptable
                    else
                    {
                        unitsToMake = target;
                    }

                    // fill shift if possible
                    if (unitsToMake < maxInShift && unitsToMake < max)
                    {
                        unitsToMake = maxInShift;
                    }
                }
            }
            else // create by units
            {
                max    = nextItem.MaxSupply;
                min    = nextItem.MinSupply;
                target = nextItem.TargetSupply;
                if (target == 0)
                {
                    unitsToMake = // run to order. Get sum of orders
                                  StaticInventoryTracker.SalesItems.Where(sale => sale.MasterID == nextItem.MasterID && sale.Date < GenerationSettings.SalesOutlook && sale.Units - sale.Fulfilled < 1).Sum(sale => sale.Units - sale.Fulfilled);
                }
                else
                {
                    if (target + currentInv < min) // target too small
                    {
                        unitsToMake = min;
                    }
                    else if (target + currentInv > max) // target too big
                    {
                        unitsToMake = max;
                    }
                    else
                    {
                        unitsToMake = target;
                    }

                    // Make enough to fill the shift by default

                    double make = unitsToMake;

                    do
                    {
                        make -= nextItem.UnitsPerHour * 8; // 8 hours in a shift by default

                        if (make < 0)
                        {
                            unitsToMake += -(make); // add enough to cover shift.
                        }
                    } while (make > 0);
                }
            }

            if (unitsToMake > maxInShift)
            {
                unitsToMake = maxInShift;
            }
            // try to fill shift
            if (unitsToMake < maxInShift && unitsToMake < max)
            {
                unitsToMake = maxInShift;
            }

            return((int)unitsToMake); // round to nearest unit
        }
Пример #14
0
        public async Task <IEnumerable <ForecastItem> > GetNextFiveDaysWeather(string cityName, Unit unit = Unit.Standard, Language language = Language.en)
        {
            var reqUrl   = _requestBuilder.GetForecastUri(cityName, unit, language);
            var forecast = await RestClient.GetAsync <WeatherForecast>(reqUrl);

            var list = forecast.List
                       .Select(forecastListItem => new ForecastItem
            {
                Date        = Convertions.UnixTimeStampToDateTime(forecastListItem.LastUpdate).ToString("dd/MM/yyyy"),
                Temperature = forecastListItem.Main.Temperature,
                Description = forecastListItem.Weather[0]?.Description
            });

            return(list.GroupBy(forecastItem => forecastItem.Date).Select(ForecastItem => ForecastItem.First()).ToArray());
        }