Exemplo n.º 1
0
        public async Task GetOutput(HttpContext context, System.IO.Stream outputStream, IEnumerable <Common.Model.ChargePoint> dataList, Common.APIRequestParams settings)
        {
            if (settings.APIVersion >= 2)
            {
                var featureCollection = new GeoJSONFeatureCollection();
                foreach (var poi in dataList)
                {
                    var feature = new GeoJSONFeature();
                    feature.ID = poi.ID.ToString();
                    feature.Geometry.Coordinates = new double[] { poi.AddressInfo.Longitude, poi.AddressInfo.Latitude };

                    Common.Model.ConnectionInfo maxConnection = null;
                    if (poi.Connections != null)
                    {
                        maxConnection = poi.Connections.OrderByDescending(p => p.LevelID).FirstOrDefault();
                    }

                    var featureProperties = new Dictionary <string, object> {
                        { "Name", poi.AddressInfo.Title },
                        { "Description", poi.AddressInfo.ToString() },
                        { "URL", "https://openchargemap.org/site/poi/details/" + poi.ID },
                        { "Level", (maxConnection != null && maxConnection.LevelID != null?maxConnection.LevelID.ToString():null) },
                        { "ConnectionType", (maxConnection != null && maxConnection.ConnectionType != null?maxConnection.ConnectionType.Title:null) },
                    };

                    if (settings.IsVerboseOutput)
                    {
                        featureProperties.Add("POI", poi);
                    }
                    feature.Properties = featureProperties;

                    featureCollection.Features.Add(feature);
                }

                System.IO.StreamWriter s = new StreamWriter(outputStream);

                if (settings.Callback != null)
                {
                    await s.WriteAsync(settings.Callback + "(");
                }

                var serializerSettings = GetSerializerSettings(settings);

                //enforce camelcasing
                serializerSettings.ContractResolver  = new CamelCasePropertyNamesContractResolver();
                serializerSettings.NullValueHandling = NullValueHandling.Ignore;

                string json = JsonConvert.SerializeObject(featureCollection, serializerSettings);
                await s.WriteAsync(json);

                if (settings.Callback != null)
                {
                    await s.WriteAsync(")");
                }

                await s.FlushAsync();
            }
        }
Exemplo n.º 2
0
        public static double?ComputePowerkW(Common.Model.ConnectionInfo cinfo)
        {
            var powerkW = cinfo.PowerKW;

            if (cinfo.Amps > 0 && cinfo.Voltage > 0)
            {
                if (cinfo.CurrentTypeID == null || cinfo.CurrentTypeID == (int)StandardCurrentTypes.SinglePhaseAC || cinfo.CurrentTypeID == (int)StandardCurrentTypes.DC)
                {
                    powerkW = ((double)cinfo.Amps * (double)cinfo.Voltage / 1000);
                }
                else
                {
                    powerkW = ((double)cinfo.Amps * (double)cinfo.Voltage * 1.732 / 1000);
                }

                powerkW = Math.Round((double)powerkW, 1);
            }

            return(powerkW);
        }