Exemple #1
0
        // Has to be run by UI context!
        public void loadDict2Sites(string aqName)
        {
            var isSiteUninit = sites.Count() == 0;

            // if sites is uninitialized.
            if (isSiteUninit)
            {
                foreach (var s in m.sitesStrDict)
                {
                    var siteDict = s.Value;
                    sites.Add(new SiteViewModel
                    {
                        siteName = s.Key,
                        county   = s.Value["County"],
                        twd97Lat = double.Parse(siteDict["TWD97Lat"]),
                        twd97Lon = double.Parse(siteDict["TWD97Lon"]),
                    });
                }
            }

            foreach (var site in sites)
            {
                var circleText = m.sitesStrDict[site.siteName][aqName];
                if (aqName == "PublishTime")
                {
                    circleText = circleText.Substring(11, 5);
                }
                var aqLevel = m.getAqLevel(site.siteName, aqName);
                site.aqi         = m.getValidAqVal(m.sitesStrDict[site.siteName]["AQI"]);
                site.CircleColor = StaticTaqModel.aqColors[aqName][aqLevel];
                site.CircleText  = site.siteName + "\n" + circleText;
                site.ListText    = m.sitesStrDict[site.siteName][aqName];
                site.TextColor   = StaticTaqModelView.getTextColor(aqLevel);
            }
        }
Exemple #2
0
        // id == 0 stands for main site aqgv.
        public void updateAqgv(int id)
        {
            var siteName = m.subscrSiteList[id];
            var aqvms    = aqvmsList[id];

            var i = 0;

            foreach (var k in StaticTaqModel.fieldNames.Keys)
            {
                var aqLevel   = m.getAqLevel(siteName, k);
                var textColor = StaticTaqModelView.getTextColor(aqLevel);
                aqvms[i].CircleColor = StaticTaqModel.aqColors[k][aqLevel];
                aqvms[i].CircleText  = StaticTaqModel.fieldNames[k] + "\n" + m.sitesStrDict[siteName][k];
                aqvms[i].TextColor   = textColor;
                i++;
            }
        }
Exemple #3
0
        public object Convert(object value, Type targetType, object parameter, string culture)
        {
            var aqLevel = StaticTaqModel.getAqLevel(AqHistShared.aqName, double.Parse((string)value));

            return(StaticTaqModelView.getTextColor(aqLevel));
        }
Exemple #4
0
        // Convert site info to AqViewModel for data bindings.
        public ObservableCollection <UIElement> loadSite2Aqvm(string siteName)
        {
            var aqvms  = new ObservableCollection <AqViewModel>();
            var aqgvis = new ObservableCollection <UIElement>();

            foreach (var k in StaticTaqModel.fieldNames.Keys)
            {
                var aqLevel   = m.getAqLevel(siteName, k);
                var textColor = StaticTaqModelView.getTextColor(aqLevel);
                var aqvm      = new AqViewModel
                {
                    CircleColor = StaticTaqModel.aqColors[k][aqLevel], // default border background color
                    CircleText  = StaticTaqModel.fieldNames[k] + "\n" + m.sitesStrDict[siteName][k],
                    TextColor   = textColor
                };
                aqvms.Add(aqvm);

                // Create UIElement for GridViewItem by k value.
                switch (k)
                {
                case "PM2.5":
                case "PM2.5_AVG":
                    aqgvis.Add(new GridPm2_5(aqvm));
                    break;

                case "PM10":
                case "PM10_AVG":
                    aqgvis.Add(new GridPm10(aqvm));
                    break;

                case "O3":
                case "O3_8hr":
                    aqgvis.Add(new Grid1(aqvm, "O", "3", "ppb"));
                    break;

                case "CO":
                case "CO_8hr":
                    aqgvis.Add(new Grid1(aqvm, "CO", "", "ppm"));
                    break;

                case "SO2":
                    aqgvis.Add(new Grid1(aqvm, "SO", "2", "ppb"));
                    break;

                case "NO2":
                    aqgvis.Add(new Grid1(aqvm, "NO", "2", "ppb"));
                    break;

                case "NOx":
                    aqgvis.Add(new Grid1(aqvm, "NO", "x", "ppb"));
                    break;

                case "NO":
                    aqgvis.Add(new Grid1(aqvm, "NO", "", "ppb"));
                    break;

                case "WindSpeed":
                    aqgvis.Add(new Grid1(aqvm, "", "", "m/s"));
                    break;

                case "WindDirec":
                    aqgvis.Add(new Grid1(aqvm, "", "", "°"));
                    break;

                default:
                    aqgvis.Add(new Grid1(aqvm, "", "", ""));
                    break;
                }
            }
            aqvmsList.Add(aqvms);
            return(aqgvis);
        }
Exemple #5
0
        public async Task <int> genTileImages(string siteName)
        {
            // Get colors by AQI.
            var aqName  = aqHistNames[(int)localSettings.Values["TileBackColorAqId"]];
            var aqLevel = getAqLevel(siteName, aqName);
            // Remove '#'.
            var rectColorStr = StaticTaqModel.aqColors[aqName][aqLevel].Substring(1);
            var r            = (byte)Convert.ToUInt32(rectColorStr.Substring(0, 2), 16);
            var g            = (byte)Convert.ToUInt32(rectColorStr.Substring(2, 2), 16);
            var b            = (byte)Convert.ToUInt32(rectColorStr.Substring(4, 2), 16);
            var bgColor      = new SolidColorBrush(Color.FromArgb(0xFF, r, g, b));
            var textColor    = StaticTaqModelView.getTextColor(aqLevel);

            // Extract time.
            var dateStr   = sitesStrDict[siteName]["PublishTime"].Substring(5, 5).Replace("-", "/");
            var timeStr   = sitesStrDict[siteName]["PublishTime"].Substring(11, 5);
            var aqiStr    = sitesStrDict[siteName]["AQI"];
            var pm2_5_Str = sitesStrDict[siteName]["PM2.5"];
            var pm10_Str  = sitesStrDict[siteName]["PM10"];

            // Small tile
            var smallTile = new SmallTile(textColor);

            smallTile.topTxt.Text       = siteName;
            smallTile.downTxt.Text      = timeStr;
            smallTile.border.Background = bgColor;

            // Med tile
            var medTile = new MedTile(textColor);

            medTile.topTxt.Text       = siteName;
            medTile.topVal.Text       = timeStr;
            medTile.medVal.Text       = aqiStr;
            medTile.downVal.Text      = pm2_5_Str;
            medTile.border.Background = bgColor;

            // Wide tile
            var wideTile = new WideTile(textColor);

            wideTile.topTxt.Text       = siteName + "-" + dateStr + "-" + timeStr;
            wideTile.medVal1.Text      = aqiStr;
            wideTile.medVal2.Text      = pm2_5_Str;
            wideTile.medVal3.Text      = pm10_Str;
            wideTile.border.Background = bgColor;

            // Large tile
            var largeTile = new LargeTile(textColor);

            largeTile.val1.Text         = siteName;
            largeTile.val2.Text         = sitesStrDict[siteName]["ShortStatus"];
            largeTile.val3_1.Text       = dateStr;
            largeTile.val3_2.Text       = timeStr;
            largeTile.val4.Text         = aqiStr;
            largeTile.val5.Text         = pm2_5_Str;
            largeTile.val6.Text         = pm10_Str;
            largeTile.val7.Text         = sitesStrDict[siteName]["O3"];
            largeTile.val8.Text         = sitesStrDict[siteName]["CO"];
            largeTile.val9.Text         = sitesStrDict[siteName]["SO2"];
            largeTile.border.Background = bgColor;

            await StaticTaqModelView.saveUi2Png(siteName + "SmallTile.png", smallTile);

            await StaticTaqModelView.saveUi2Png(siteName + "MedTile.png", medTile);

            await StaticTaqModelView.saveUi2Png(siteName + "WideTile.png", wideTile);

            await StaticTaqModelView.saveUi2Png(siteName + "LargeTile.png", largeTile);

            return(0);
        }