コード例 #1
0
ファイル: MainPageWeather.cs プロジェクト: yookjy/Chameleon
        void weatherBug_LiveWeatherCompleted(object sender, LiveWeather liveWeather, Forecasts forecasts)
        {
            //도시검색을 통해서 들어온 경우라면 폰상태 정보의 도시정보를 설정에 저장하고 삭제
            if (PhoneApplicationService.Current.State.ContainsKey(Constants.WEATHER_MAIN_CITY))
            {
                SettingHelper.Set(Constants.WEATHER_MAIN_CITY, PhoneApplicationService.Current.State[Constants.WEATHER_MAIN_CITY], true);
                PhoneApplicationService.Current.State.Remove(Constants.WEATHER_MAIN_CITY);
            }

            if (liveWeather == null || !(liveWeather is LiveWeather) || forecasts == null || !(forecasts is Forecasts))
            {
                WeatherCity city = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity;

                PIWeather.Header            = city.IsGpsLocation ? AppResources.Refresh : city.CityName;
                GridLiveWeather.Visibility  = System.Windows.Visibility.Collapsed;
                ListBoxForecasts.Visibility = System.Windows.Visibility.Collapsed;
                TxtWeatherNoCity.Visibility = System.Windows.Visibility.Visible;
                TxtWeatherNoCity.Text       = AppResources.MsgNotSupportWeatherLocation;
                return;
            }
            //검색된 결과값 저장
            SettingHelper.Set(Constants.WEATHER_LIVE_RESULT, liveWeather, true);
            //화면에 검색된 결과를 표시
            RenderLiveWeather(liveWeather);
            //조회된 주간예보 정보를 저장
            SettingHelper.Set(Constants.WEATHER_FORECAST_RESULT, forecasts, true);
            //조회된 주간예보 정보를 화면에 표시
            RenderForecast(forecasts);
            //날씨 라이브타일 다시 로드
            CreateWeatherLivetileImage();

            //로딩 레이어 제거
            HideLoadingPanel();
        }
コード例 #2
0
        private async Task OnForcastDue(ForecastDueEvent eventArgs)
        {
            Forecasts.Remove(eventArgs.Forecast);

            await _weatherService.RetrieveForcastWeatherData()
            .ContinueWith(async forcasts => UpdateForecastWeatherData(await forcasts), TaskScheduler.FromCurrentSynchronizationContext());
        }
コード例 #3
0
        private void btnImportFile_Click(object sender, RoutedEventArgs e)
        {
            var mbresult = MessageBox.Show("Vid import av ny fil kommer befintlig uppföljningsdata att skrivas över. Fortsätta?",
                                           "Import av fil", MessageBoxButton.YesNo);

            if (mbresult == MessageBoxResult.Yes)
            {
                try
                {
                    OpenFileDialog ofd = new OpenFileDialog
                    {
                        Filter      = "Textfiler (.txt)|*.txt",
                        Title       = "Importera IntäktProduktKund.txt",
                        Multiselect = false
                    };

                    var result = ofd.ShowDialog();

                    if (result == true)
                    {
                        ForecastingManagement.Instance.CreateForecastFromFile(ofd.FileName);
                        Forecasts.Clear();
                        cbMonth_SelectionChanged(sender, e as SelectionChangedEventArgs);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #4
0
        WeatherForecast[] UpdateInternal(WeatherForecast dataItem, Dictionary <string, object> newValue)
        {
            foreach (var field in newValue.Keys)
            {
                switch (field)
                {
                case "Date":
                    dataItem.Date = (DateTime)newValue[field];
                    break;

                case "Summary":
                    dataItem.Summary = (string)newValue[field];
                    break;

                case "TemperatureC":
                    int intValue = 0;
                    if (Int32.TryParse((string)newValue[field], out intValue))
                    {
                        dataItem.TemperatureC = intValue;
                    }
                    break;
                }
            }
            return(Forecasts.ToArray());
        }
コード例 #5
0
        WeatherForecast[] UpdateInternal(WeatherForecast dataItem, IDictionary <string, object> newValue)
        {
            foreach (var field in newValue.Keys)
            {
                switch (field)
                {
                case nameof(dataItem.Date):
                    dataItem.Date = (DateTime)newValue[field];
                    break;

                case nameof(dataItem.Summary):
                    dataItem.Summary = (string)newValue[field];
                    break;

                case nameof(dataItem.TemperatureC):
                    dataItem.TemperatureC = (int)newValue[field];
                    break;

                case nameof(dataItem.Precipitates):
                    dataItem.Precipitates = (bool)newValue[field];
                    break;

                case nameof(dataItem.WeatherType):
                    dataItem.WeatherType = (string)newValue[field];
                    break;
                }
            }
            return(Forecasts.ToArray());
        }
コード例 #6
0
        public void GetForecastsFromMonth(DateTime month, bool getAll)
        {
            List <IncomeProductCustomer> IPCs;

            if (getAll)
            {
                // Hämta inte från månad utan från alla
                IPCs = new List <IncomeProductCustomer>(GetAllIPCs());

                // Lägg till produkter från vårat system
                var AllProducts = GetAllProducts();

                // Lägg till alla produkter från systemet genom att fejka tomma ICPs
                // (Fulhack)
                IPCs.AddRange(AllProducts.Select(productObj => new IncomeProductCustomer
                {
                    IeProductID    = productObj.ProductID,
                    IeCustomerID   = "NULL",
                    IeCustomerName = "NULL",
                    IeIncomeDate   = new DateTime(1973, 10, 24),
                    IeProductName  = productObj.ProductName
                }));

                // Order by product name
                IPCs = IPCs.OrderBy(p => p.IeProductName).ToList();
            }
            else
            {
                IPCs = new List <IncomeProductCustomer>(GetIPCsByMonth(month));
            }

            // Aj, inte så fin lista på redan tillagda produkter (då ska inte IPCn läggas in igen)
            List <string> tempProdukter = new List <string>();


            foreach (var IPC in IPCs)
            {
                if (!tempProdukter.Contains(IPC.IeProductID))
                {
                    Forecasting fc = new Forecasting
                    {
                        IeProductID     = IPC.IeProductID,
                        IeProductName   = IPC.IeProductName,
                        OutcomeAcc      = CalculateUtfallAcc(month, IPC.IeProductID),
                        Trend           = ((CalculateUtfallAcc(month, IPC.IeProductID) + GetReprocessedValue(month, IPC.IeProductID)) / month.Month) * 12,
                        FormerPrognosis = GetFormerForecastValue(month, IPC.IeProductID),
                        Forecast        = GetForecastValue(month, IPC.IeProductID),
                        OutcomeMonth    = CalculateOutcomeMonth(month.Month, IPC.IeProductID),
                        Budget          = GetBudgetFromFinancialIncome(IPC.IeProductID),
                        Reprocessed     = GetReprocessedValue(month, IPC.IeProductID)
                    };

                    // Add to the returning list
                    Forecasts.Add(fc);

                    // Vi ska inte använda den här igen
                    tempProdukter.Add(IPC.IeProductID);
                }
            }
        }
コード例 #7
0
        async Task ExecuteLoadItemsCommand(City city)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy    = true;
            IsNotBusy = false;

            try
            {
                Forecasts.Clear();
                forecast = await DataStore.GetForecast(city.Location.Name + "," + city.Location.Region + "," + city.Location.Country);

                foreach (var f in forecast.Forecast.Forecastday)
                {
                    f.IsFah     = IsFah;
                    f.IsCelsius = IsCelsius;
                    Forecasts.Add(f);
                }

                OnPropertyChanged("forecast");
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy    = false;
                IsNotBusy = true;
            }
        }
コード例 #8
0
        WeatherForecast[] InsertInternal(IDictionary <string, object> newValue)
        {
            var dataItem = new WeatherForecast();

            Update(dataItem, newValue);
            Forecasts.Insert(0, dataItem);
            return(Forecasts.ToArray());
        }
コード例 #9
0
        protected override async Task OnInitAsync()
        {
            Console.WriteLine("OnInitAsync");
            Forecasts = await Http.GetJsonAsync <WeatherForecast[]>("api/SampleData/WeatherForecasts");

            // Default Sort
            CurrentSortColumn = "Date";
            Forecasts         = Forecasts.OrderBy(x => x.Date).ToArray();
        }
コード例 #10
0
        /// <summary>
        /// Creates a forecasting from the imported file IntaktProduktKund.txt
        /// </summary>
        /// <param name="fileName"></param>
        public void CreateForecastFromFile(string fileName)
        {
            // First, delete all forecast related items in db
            db.ForecastMonitor.RemoveRange(db.ForecastMonitor);
            db.ForecastMonth.RemoveRange(db.ForecastMonth);
            db.IncomeProductCustomer.RemoveRange(db.IncomeProductCustomer);
            db.SaveChanges();
            Forecasts.Clear();

            using (var reader = new StreamReader(fileName, Encoding.Default))
            {
                // Ignore first row since it's a header
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    string row = reader.ReadLine();

                    if (!String.IsNullOrEmpty(row))
                    {
                        /* IntaktProduktKund.txt is formatted in such a way that there are up to three tabs separating each
                         * 'column' in the text file. If a row contains multiple tabs they are replaced with one. */
                        if (row.Contains("\t\t\t"))
                        {
                            row = row.Replace("\t\t\t", "\t");
                        }

                        if (row.Contains("\t\t"))
                        {
                            row = row.Replace("\t\t", "\t");
                        }

                        if (row.Contains("  "))
                        {
                            row = row.Replace("  ", "\t");
                        }

                        // At this point each column is only separated by one tab which makes it easy to read the file
                        string[] field = row.Split('\t');

                        IncomeProductCustomer ipc = new IncomeProductCustomer();
                        ipc.IeProductID    = field[0];
                        ipc.IeProductName  = field[1];
                        ipc.IeCustomerID   = field[2];
                        ipc.IeCustomerName = field[3];
                        ipc.IeAmount       = int.Parse(field[5]);
                        ipc.IeIncomeDate   = DateTime.ParseExact(field[4], "yyyyMMdd", CultureInfo.InvariantCulture);



                        // Add icp to database
                        AddIncomeProductCustomer(ipc);
                        //CreateForecasting(ipc);
                    }
                }
            }
        }
コード例 #11
0
ファイル: WeatherVM.cs プロジェクト: RodolfoJZuluaga/Weather
        private async void GetWeather()
        {
            var weather = await WeatherAPI.GetWeatherInformationAsync(SelectedCity.Key);

            Forecasts.Clear();
            foreach (var w in weather.DailyForecasts)
            {
                Forecasts.Add(w);
            }
        }
 public SolradNwpForecast ToSolradNwpForecast()
 {
     return(new SolradNwpForecast
     {
         Created = Created,
         Modified = Modified,
         Latitude = Latitude,
         Longitude = Longitude,
         Srid = Srid,
         Forecasts = Forecasts.Select(f => f.ToSolradForecast()).ToList()
     });
 }
コード例 #13
0
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

        protected override void OnInitialized()
        {
            Logger.Here(l => l.Entering());

            base.OnInitialized();

            Context       = ContextFactory.Create();
            Forecasts     = Context.Forecasts.AsQueryable();
            ForecastsList = Forecasts.ToList();

            Logger.Here(l => l.Exiting());
        }
コード例 #14
0
ファイル: Index.cshtml.cs プロジェクト: adrwer/ondotnet
        public async Task OnGet([FromServices] WeatherClient client)
        {
            Forecasts = await client.GetWeatherAsync();

            if (Forecasts.Count() == 0)
            {
                ErrorMessage = "We are unable to fetch weather info right now. Please try again after some time.";
            }
            else
            {
                ErrorMessage = string.Empty;
            }
        }
コード例 #15
0
        public MonthLog(BudgetLogType log,
                        YearMonth when,
                        IMoneyCalculator calculator,
                        IEnumerable <Transaction> actual = null,
                        IEnumerable <Forecast> forecast  = null)
        {
            When         = when;
            Transactions = actual?.Where(n => n.Log == log).ToList() ?? new List <Transaction>();
            Forecasts    = forecast?.Where(n => n.Log == log).ToList() ?? new List <Forecast>();

            Total = FinancialStats.GetTotal(calculator,
                                            Transactions.Select(n => n.Amount),
                                            Forecasts.Select(n => n.Amount));
        }
コード例 #16
0
        public async void GetWeather()
        {
            var weather = await WeatherAPI.GetWeatherInformationAsync(SelectedCity.Key);

            if (weather.DailyForecasts != null)
            {
                Forecasts.Clear();

                foreach (var forcast in weather.DailyForecasts)
                {
                    Forecasts.Add(forcast);
                }
            }
        }
コード例 #17
0
        public async void GetWeather()
        {
            //will initiate null - pending item selection
            var weather = await WeatherAPI.GetWeatherInformationAsync(SelectedResult.Key);

            if (weather.DailyForecasts != null)
            {
                Forecasts.Clear();
                //loop through API received forcasts adding each to Forecast collection
                foreach (var forecast in weather.DailyForecasts)
                {
                    Forecasts.Add(forecast);
                }
            }
        }
コード例 #18
0
        public async void GetWeather()      //Build list of Forecats from API
        {
            Forecasts.Clear();
            if (SelectedResult != null)
            {
                var weather = await WeatherAPI.GetWeatherInformationAsync(SelectedResult.Key);

                if (weather.DailyForecasts != null)
                {
                    foreach (var forecast in weather.DailyForecasts)
                    {
                        Forecasts.Add(forecast);
                    }

                    //TODO: implement radio button to convert forecast values from C to F
                }
            }
        }
コード例 #19
0
        private async void GetWeather()
        {
            if (!string.IsNullOrEmpty(selectedCity.Key))
            {
                var weather = await WeatherAPI.GetWeatherInformationAsync(selectedCity.Key);

                Weather.DailyForecasts = weather.DailyForecasts;
            }

            Forecasts.Clear();
            if (Weather.DailyForecasts != null)
            {
                foreach (var forecast in Weather.DailyForecasts)
                {
                    Forecasts.Add(forecast);
                }
            }
        }
コード例 #20
0
        private void UpdateForecasts(bool getAll = false)
        {
            getAll = (bool)cbshowAll.IsChecked;

            Forecasts.Clear();

            Months SelectedMonth;

            Enum.TryParse(cbMonth.SelectedValue.ToString(), out SelectedMonth);

            //string date = "01/01/2013";

            //DateTime dt = Convert.ToDateTime(DateTime.);

            DateTime month = new DateTime(DateTime.Now.Year, (int)SelectedMonth, 1);

            // Adda en month för att kunna låsa (addas bara om den inte finns)
            ForecastMonth = ForecastingManagement.Instance.AddForecastMonth(month);



            ForecastingManagement.Instance.GetForecastsFromMonth(month, getAll);

            UpdateLabels();

            if (Forecasts.Any())
            {
                if (ForecastingManagement.Instance.CheckIfLocked(month))
                {
                    dgForecasts.IsEnabled = false;
                    btnSave.IsEnabled     = false;
                    lblInfo.Content       = "Uppföljning för denna månad är låst";
                    btnLock.IsEnabled     = false;
                }
                else
                {
                    dgForecasts.IsEnabled = true;
                    btnSave.IsEnabled     = true;
                    btnLock.IsEnabled     = true;
                    lblInfo.Content       = "";
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// Change the data of the Forecasts ObservableCollection
        /// so that the view can bind
        /// </summary>
        public async void GetWeather()
        {
            if (SelectedCity != null)
            {
                string key = SelectedCity.Key;
                try {
                    var weather = await WeatherAPI.GetWeatherInformationAsync(SelectedCity.Key);

                    Forecasts.Clear();
                    foreach (var forecast in weather.DailyForecasts)
                    {
                        Forecasts.Add(forecast);
                    }
                }
                catch (System.Net.Http.HttpRequestException) {
                    ShowMessageBox();
                }
            }
        }
コード例 #22
0
ファイル: ScheduledAgent.cs プロジェクト: yookjy/Chameleon
        private void SetWeatherResult(LiveData data, LiveWeather liveWeather, Forecasts forecasts)
        {
            if (liveWeather != null)
            {
                data.LiveWeather = liveWeather;
            }
            else
            {
                data.LiveWeather = (LiveWeather)SettingHelper.Get(Constants.WEATHER_LIVE_RESULT);
            }

            if (forecasts != null)
            {
                data.Forecasts = forecasts;
            }
            else
            {
                data.Forecasts = (Forecasts)SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT);
            }
        }
    void DisplayForecast(Forecasts forecasts)
    {
        List <float> valueList = new List <float>();

        gameObjectList = new List <GameObject>();

        for (var i = 0; i < forecasts.forecasts.Length; i++)
        {
            valueList.Add(forecasts.forecasts[i].pred_value);
        }

        if (valueList.Count > 0)
        {
            ShowGraph(valueList, -1, (float _i) => "Month " + (_i), (float _f) => "$" + _f);
        }
        else
        {
            noProductsPopup.SetActive(true);
        }
    }
コード例 #24
0
        public async void GetForecasts()
        {
            var locations      = database.GetLocations();
            var weatherService = new WeatherService();

            Forecasts.Clear();
            foreach (var location in locations)
            {
                var forecast = await weatherService.GetForecast(location.Key);

                if (forecast != null)
                {
                    Forecasts.Add(new ForecastWrapper(forecast, location.LocalizedName));
                }
                else
                {
                    database.DeleteLocation(location.Id);
                }
            }
        }
コード例 #25
0
ファイル: MainPageWeather.cs プロジェクト: yookjy/Chameleon
        private void RenderForecast(Forecasts forecasts)
        {
            if (forecasts != null && forecasts.Items.Count > 0)
            {
                List <Forecast> items = forecasts.Items.ToList <Forecast>();
                items.Insert(0, forecasts.Today);

                ListBoxForecasts.ItemsSource = items;
                ListBoxForecasts.Visibility  = System.Windows.Visibility.Visible;

                ListBoxNightForecasts.ItemsSource = items;
                ListBoxNightForecasts.Visibility  = System.Windows.Visibility.Collapsed;
            }
            else
            {
                ListBoxForecasts.ItemsSource = null;
                ListBoxForecasts.Visibility  = System.Windows.Visibility.Collapsed;

                ListBoxNightForecasts.ItemsSource = null;
                ListBoxNightForecasts.Visibility  = System.Windows.Visibility.Collapsed;
            }
        }
コード例 #26
0
        public async Task OnGet([FromServices] WeatherClient client)
        {
            string query = "12.9716,77.5946";

            if (!String.IsNullOrEmpty(Request.Query["query"]))
            {
                query = Request.Query["query"];
            }

            Console.WriteLine($"query -- {query}");

            Forecasts = await client.GetWeatherAsync(query);

            if (Forecasts.Count() == 0)
            {
                ErrorMessage = "We are unable to fetch weather info right now. Please try again after some time.";
            }
            else
            {
                ErrorMessage = string.Empty;
            }
        }
コード例 #27
0
        private async Task UpdateForecastWeatherData(IEnumerable <Forecast> forecasts)
        {
            forecasts = forecasts.OrderBy(f => f.Date).Where(f => f.Date > DateTime.Now && f.Date.Date >= DateTime.Today && f.Date.Date <= DateTime.Today.AddDays(1));

            foreach (var forecast in forecasts.Take(FORCAST_LENGHT))
            {
                var existingForcastVM = Forecasts.FirstOrDefault(f => f.Date == forecast.Date);

                if (existingForcastVM != null)
                {
                    existingForcastVM.Update(forecast);
                }
                else
                {
                    var icons = GetIcons(forecast.Date.TimeOfDay, _dawn, _dusk);

                    var forecastVM = new ForecastViewModel(forecast, icons);

                    Forecasts.Add(forecastVM);

                    await forecastVM.Init();
                }
            }
        }
コード例 #28
0
ファイル: MainPageWeather.cs プロジェクト: yookjy/Chameleon
        private void RetrieveWeather()
        {
            WeatherCity city = SettingHelper.Get(Constants.WEATHER_MAIN_CITY) as WeatherCity;

            if (SettingHelper.ContainsKey(Constants.WEATHER_LIVE_RESULT))
            {
                LiveWeather liveWeather = SettingHelper.Get(Constants.WEATHER_LIVE_RESULT) as LiveWeather;

                System.DateTime updDttm = GetDateTime(liveWeather.ObDate);
                //System.DateTime updDttm = liveWeather.UpdatedDateTime;

                //업데이트 후 1시간이 지나지 않았다면
                if (DateTime.Now.Subtract(updDttm).TotalMinutes < 60)
                {
                    //도시 설정
                    weatherBug.DefaultWeatherCity = city;
                    //화면 표시
                    RenderLiveWeather(liveWeather);

                    //업데이트 불필요 기존 데이터를 다시 로드하여 보여줌
                    if (SettingHelper.ContainsKey(Constants.WEATHER_FORECAST_RESULT))
                    {
                        Forecasts forecasts = SettingHelper.Get(Constants.WEATHER_FORECAST_RESULT) as Forecasts;

                        //주간 예보 표시
                        RenderForecast(forecasts);
                        return;
                    }
                }
            }

            if (city != null)
            {
                RetrieveWeather(city);
            }
        }
 private void Forecast_onGetForecast(Forecasts response)
 {
     DisplayForecast(response);
     forecast.onGetForecast -= Forecast_onGetForecast;
     loadingPopup.SetActive(false);
 }
コード例 #30
0
 /// <summary>
 /// Calculates the trend in a specific forecast object
 /// </summary>
 /// <param name="forecast"></param>
 /// <param name="passedMonths"></param>
 public void CalculateTrend(Forecasting forecast, int passedMonths)
 {
     forecast.Trend = ((forecast.OutcomeAcc + forecast.Reprocessed) / passedMonths) * 12;
     Forecasts.Single(f => f.Equals(forecast)).Trend = forecast.Trend;
 }