Exemple #1
0
        public void SensorIdUInt32ConstructorTest()
        {
            var _SensorId = new SensorId(23U);

            Assert.AreEqual("23", _SensorId.ToString());
            Assert.AreEqual(2, _SensorId.Length);
        }
Exemple #2
0
        public void SensorIdStringConstructorTest()
        {
            var _SensorId = new SensorId("123");

            Assert.AreEqual("123", _SensorId.ToString());
            Assert.AreEqual(3, _SensorId.Length);
        }
Exemple #3
0
        public void SensorIdInt32ConstructorTest()
        {
            var _SensorId = new SensorId(5);

            Assert.AreEqual("5", _SensorId.ToString());
            Assert.AreEqual(1, _SensorId.Length);
        }
Exemple #4
0
        public void SensorIdUriConstructorTest()
        {
            var _SensorId = new SensorId(new Uri("http://example.org"));

            Assert.AreEqual("http://example.org/", _SensorId.ToString());
            Assert.AreEqual(19, _SensorId.Length);
        }
Exemple #5
0
        public void SensorIdInt64ConstructorTest()
        {
            var _SensorId = new SensorId(42L);

            Assert.AreEqual("42", _SensorId.ToString());
            Assert.AreEqual(2, _SensorId.Length);
        }
Exemple #6
0
        public void SensorIdSensorIdConstructorTest()
        {
            var _SensorId1 = SensorId.NewSensorId;
            var _SensorId2 = new SensorId(_SensorId1);

            Assert.AreEqual(_SensorId1.ToString(), _SensorId2.ToString());
            Assert.AreEqual(_SensorId1.Length, _SensorId2.Length);
            Assert.AreEqual(_SensorId1, _SensorId2);
        }
        internal static void UpdateSensorNamesCache(List <int> i_SensorIds)
        {
            verifyLoggedInStatus();

            if (i_SensorIds.Count < 1)
            {
                throw new ArgumentException("List must contain at least one value");
            }

            HttpClient client = BaseHttpClient();

            client.DefaultRequestHeaders.TryAddWithoutValidation("X-ACCESS-TOKEN", InnoviApiService.AccessToken);
            string        baseUri           = Settings.ApiVersionEndpoint + "sensors/list?";
            var           httpRequest       = new HttpRequestMessage(HttpMethod.Get, baseUri);
            StringBuilder requestUriBuilder = new StringBuilder();

            requestUriBuilder.Append(baseUri);
            int sensorCount = 0;
            Dictionary <int, int> addedSensors = new Dictionary <int, int>();

            Cache cache = Cache.Fetch();

            foreach (int SensorId in i_SensorIds)
            {
                if (!addedSensors.ContainsKey(SensorId))
                {
                    addedSensors.Add(SensorId, 0);

                    if (sensorCount++ > 0)
                    {
                        requestUriBuilder.Append("&");
                    }

                    requestUriBuilder.Append("id=" + SensorId.ToString());
                }
            }

            httpRequest.RequestUri = new Uri(requestUriBuilder.ToString(), UriKind.Relative);

            Task <HttpResponseMessage> result   = client.SendAsync(httpRequest);
            HttpResponseMessage        response = result.Result;
            JObject responseJsonObject          = GetHttpResponseBody(response);

            verifyCodeZero(responseJsonObject);
            InnoviApiService.RefreshAccessToken(response);
            List <Sensor> sensors = JsonConvert.DeserializeObject <List <Sensor> >(responseJsonObject["list"].ToString());



            List <string> sensorNames = new List <string>();

            foreach (Sensor sensor in sensors)
            {
                cache.AddToSensorCache(sensor.sensorId, sensor.Name);
            }
        }
Exemple #8
0
        public IEnumerable <Measurements> GetData()
        {
            var measurements = new List <SensorModel>();

            for (int days = 1; days >= 0; days--)
            {
                WebClient webClient         = new WebClient();
                string    station           = SensorId.ToString();
                DateTime  dateOfMeasurement = DateTime.Now.AddDays(-days);
                string    month             = (dateOfMeasurement.Month.ToString().Length == 1) ? ("0" + dateOfMeasurement.Month.ToString()) : dateOfMeasurement.Month.ToString();
                string    day        = (dateOfMeasurement.Day.ToString().Length == 1) ? ("0" + dateOfMeasurement.Day.ToString()) : dateOfMeasurement.Day.ToString();
                string    dateForUrl = dateOfMeasurement.Year.ToString() + "-" + month + "-" + day;
                string    page       = webClient.DownloadString("http://armaag.gda.pl/komunikat1h.htm?station=" + station + "&date=" + dateForUrl + "&go=poka%BF");

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(page);
                var tableHeaders = doc.DocumentNode.SelectSingleNode("//table[@class='meteotable']")
                                   .Descendants("tr")
                                   .Where(tr => tr.Elements("th").Count() > 1)
                                   .Select(tr => tr.Elements("th").Select(td => td.InnerText.Trim()
                                                                          ).ToList())
                                   .ToList();
                var table = doc.DocumentNode.SelectSingleNode("//table[@class='meteotable']")
                            .Descendants("tr")
                            .Skip(1)
                            .Where(tr => tr.Elements("td").Count() > 1)
                            .Select(tr => tr.Elements("td").Select(td => td.InnerText.Trim().Replace(":00", "")
                                                                   ).ToList())
                            .ToList();
                int hourIndex = tableHeaders[0].IndexOf("godzina");
                int pm10Index = tableHeaders[0].IndexOf("PM10");
                for (int i = 0; i < table.Count; i++)
                {
                    int hour = Int32.Parse(table[i][hourIndex].ToString()) - 1;
                    if (string.IsNullOrEmpty(table[i][pm10Index]))
                    {
                        continue;
                    }
                    measurements.Add(new Armaag(new DateTime(dateOfMeasurement.Year, dateOfMeasurement.Month, Int32.Parse(dateOfMeasurement.Day.ToString()), hour, 0, 0), Convert.ToDouble(table[i][pm10Index].Replace(".", ",")), SensorId)); //aby zadziałało lokalnie należy zamienić kropkę na przecinek, w tej wersji działa na serwerze Azure
                }
            }
            return(measurements);
        }
Exemple #9
0
 public void SensorIdUriConstructorTest()
 {
     var _SensorId = new SensorId(new Uri("http://example.org"));
     Assert.AreEqual("http://example.org/", _SensorId.ToString());
     Assert.AreEqual(19,                    _SensorId.Length);
 }
Exemple #10
0
 public void SensorIdUInt64ConstructorTest()
 {
     var _SensorId = new SensorId(123UL);
     Assert.AreEqual("123", _SensorId.ToString());
     Assert.AreEqual(3,     _SensorId.Length);
 }
Exemple #11
0
 public void SensorIdUInt32ConstructorTest()
 {
     var _SensorId = new SensorId(23U);
     Assert.AreEqual("23", _SensorId.ToString());
     Assert.AreEqual(2,    _SensorId.Length);
 }
Exemple #12
0
 public void SensorIdSensorIdConstructorTest()
 {
     var _SensorId1 = SensorId.NewSensorId;
     var _SensorId2 = new SensorId(_SensorId1);
     Assert.AreEqual(_SensorId1.ToString(), _SensorId2.ToString());
     Assert.AreEqual(_SensorId1.Length,     _SensorId2.Length);
     Assert.AreEqual(_SensorId1,            _SensorId2);
 }
Exemple #13
0
 public void SensorIdInt64ConstructorTest()
 {
     var _SensorId = new SensorId(42L);
     Assert.AreEqual("42", _SensorId.ToString());
     Assert.AreEqual(2,    _SensorId.Length);
 }
Exemple #14
0
 public void SensorIdInt32ConstructorTest()
 {
     var _SensorId = new SensorId(5);
     Assert.AreEqual("5", _SensorId.ToString());
     Assert.AreEqual(1,   _SensorId.Length);
 }
Exemple #15
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUI.changed = false;

            AppIntentProfile profile = target as AppIntentProfile;

            if (profile == null)
            {
                // Nothing we can do, so give up.
                return;
            }

            // Sensors
            EditorGUILayout.LabelField(SensorsLabel, EditorStyles.boldLabel);
            _newSensors.Clear();
            bool sensorsChanged = false;

            for (int i = 0; i < WearableConstants.SensorIds.Length; i++)
            {
                SensorId id = WearableConstants.SensorIds[i];

                bool prior = profile.GetSensorInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableConstants.EmptyLayoutOptions);
                sensorsChanged |= prior != post;

                if (post)
                {
                    _newSensors.Add(id);
                }
            }

            if (sensorsChanged)
            {
                profile.SetSensorIntent(_newSensors);
            }

            // Intervals
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(IntervalsLabel, EditorStyles.boldLabel);
            _newIntervals.Clear();
            bool intervalsChanged = false;

            for (int i = 0; i < WearableConstants.UpdateIntervals.Length; i++)
            {
                SensorUpdateInterval interval = WearableConstants.UpdateIntervals[i];
                string label = string.Format(
                    IntervalFormat,
                    ((int)WearableTools.SensorUpdateIntervalToMilliseconds(interval)).ToString());
                bool prior = profile.GetIntervalInProfile(interval);
                bool post  = EditorGUILayout.Toggle(label, prior, WearableConstants.EmptyLayoutOptions);
                intervalsChanged |= prior != post;

                if (post)
                {
                    _newIntervals.Add(interval);
                }
            }

            if (intervalsChanged)
            {
                profile.SetIntervalIntent(_newIntervals);
            }


            // Gestures
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(GesturesLabel, EditorStyles.boldLabel);

            _newGestures.Clear();
            bool gesturesChanged = false;

            for (int i = 0; i < WearableConstants.GestureIds.Length; i++)
            {
                GestureId id = WearableConstants.GestureIds[i];

                if (id == GestureId.None)
                {
                    continue;
                }

                bool prior = profile.GetGestureInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableConstants.EmptyLayoutOptions);
                gesturesChanged |= prior != post;

                if (post)
                {
                    _newGestures.Add(id);
                }
            }

            if (gesturesChanged)
            {
                profile.SetGestureIntent(_newGestures);
            }

            if (HasDeviceSpecificGesturesEnabled(profile))
            {
                EditorGUILayout.HelpBox(WearableConstants.DeviceSpecificGestureDiscouragedWarning, MessageType.Warning);
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }
Exemple #16
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            GUI.changed = false;

            AppIntentProfile profile = target as AppIntentProfile;

            if (profile == null)
            {
                // Nothing we can do, so give up.
                return;
            }

            // Sensors
            EditorGUILayout.LabelField(SENSORS_LABEL, EditorStyles.boldLabel);
            _newSensors.Clear();
            bool sensorsChanged = false;

            for (int i = 0; i < WearableConstants.SENSOR_IDS.Length; i++)
            {
                SensorId id = WearableConstants.SENSOR_IDS[i];

                bool prior = profile.GetSensorInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                sensorsChanged |= prior != post;

                if (post)
                {
                    _newSensors.Add(id);
                }
            }

            if (sensorsChanged)
            {
                profile.SetSensorIntent(_newSensors);
            }

            // Intervals
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(INTERVALS_LABEL, EditorStyles.boldLabel);
            _newIntervals.Clear();
            bool intervalsChanged = false;

            for (int i = 0; i < WearableConstants.UPDATE_INTERVALS.Length; i++)
            {
                SensorUpdateInterval interval = WearableConstants.UPDATE_INTERVALS[i];
                string label = string.Format(
                    INTERVAL_FORMAT,
                    ((int)WearableTools.SensorUpdateIntervalToMilliseconds(interval)).ToString());
                bool prior = profile.GetIntervalInProfile(interval);
                bool post  = EditorGUILayout.Toggle(label, prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                intervalsChanged |= prior != post;

                if (post)
                {
                    _newIntervals.Add(interval);
                }
            }

            if (intervalsChanged)
            {
                profile.SetIntervalIntent(_newIntervals);
            }


            // Gestures
            GUILayoutTools.LineSeparator();
            EditorGUILayout.LabelField(GESTURES_LABEL, EditorStyles.boldLabel);

            _newGestures.Clear();
            bool gesturesChanged = false;

            for (int i = 0; i < WearableConstants.GESTURE_IDS.Length; i++)
            {
                GestureId id = WearableConstants.GESTURE_IDS[i];

                if (id == GestureId.None)
                {
                    continue;
                }

                bool prior = profile.GetGestureInProfile(id);
                bool post  = EditorGUILayout.Toggle(id.ToString(), prior, WearableEditorConstants.EMPTY_LAYOUT_OPTIONS);
                gesturesChanged |= prior != post;

                if (post)
                {
                    _newGestures.Add(id);
                }
            }

            if (gesturesChanged)
            {
                profile.SetGestureIntent(_newGestures);
            }

            if (HasDeviceSpecificGesturesEnabled(profile))
            {
                EditorGUILayout.HelpBox(WearableEditorConstants.DEVICE_SPECIFIC_GESTURE_DISCOURAGED_WARNING, MessageType.Warning);
            }

            if (GUI.changed)
            {
                serializedObject.ApplyModifiedProperties();
                EditorUtility.SetDirty(target);
            }
        }