Пример #1
0
        private async Task InsertDbAsync(float Frequency,
                                         float pv_act, double pv_accum, float pcs_act, double pcs_chg_Accum, double pcs_dhg_Accum,
                                         DateTime timestamp, CancellationToken token)
        {
            try
            {
                using (var session = mysqlDataAccess.SessionFactory.OpenStatelessSession())
                    using (var trans = session.BeginTransaction())
                    {
                        TbStatus status = new TbStatus();
                        status.Date   = timestamp;
                        status.Pv     = pv_act / 1000;
                        status.PvEng  = pv_accum / 1000;
                        status.Ess    = pcs_act / 1000;
                        status.EssCh  = pcs_chg_Accum / 1000;
                        status.EssDch = pcs_dhg_Accum / 1000;
                        float[] socs         = new float[4];
                        float[] acts         = new float[4];
                        float[] pv_today_eng = new float[4];
                        int[]   pcsstatus    = new int[4];
                        for (int i = 1; i < 5; i++)
                        {
                            string redisKey = $"6.JeJuGridPcs{i}";
                            float  soc1     = (float)await redisDb.HashGetAsync(redisKey, "bms_soc");

                            float act = (float)await redisDb.HashGetAsync(redisKey, "actPwrKw");

                            pv_today_eng[i - 1] = (float)await redisDb.HashGetAsync(redisKey, "TODAY_POWER");

                            pcsstatus[i - 1] = (int)await redisDb.HashGetAsync(redisKey, "pcsstatus");

                            socs[i - 1] = soc1;
                            acts[i - 1] = act;
                        }
                        status.Soc1  = socs[0];
                        status.Soc2  = socs[1];
                        status.Soc3  = socs[2];
                        status.Soc4  = socs[3];
                        status.Stat1 = GetStat(pcsstatus[0]);
                        status.Stat2 = GetStat(pcsstatus[1]);
                        status.Stat3 = GetStat(pcsstatus[2]);
                        status.Stat4 = GetStat(pcsstatus[3]);
                        //status.Pv1_Today_Eng = pv_today_eng[0];
                        //status.Pv2_Today_Eng = pv_today_eng[1];
                        //status.Pv3_Today_Eng = pv_today_eng[2];
                        //status.Pv4_Today_Eng = pv_today_eng[3];
                        await session.InsertAsync(status);

                        await trans.CommitAsync();
                    }
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.Message);
            }
            finally
            {
                await Task.CompletedTask;
            }
        }
Пример #2
0
        private async Task <float[]> GetDeviceValues(int PcsNo, params RedisValue[] FieldNames)
        {
            string redisKey = $"6.JeJuGridPcs{PcsNo}";
            var    results  = (RedisValue[])await redisdatabaseAsync.HashGetAsync(redisKey, FieldNames);

            return(results.Select(x => (float)x).ToArray());
        }
Пример #3
0
        public async Task <IActionResult> Validate([FromRoute, EmailAddress, Required] string receiverAddress,
                                                   [FromRoute, Required] Guid?mailGuid, [FromRoute, Required] Guid?attachementGuid, [FromBody] ValidationRequest validationRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var guidString = mailGuid.HasValue ? mailGuid.Value.ToString() : "";

            if (string.IsNullOrEmpty(validationRequest.HashToValidate) || string.IsNullOrWhiteSpace(validationRequest.HashToValidate))
            {
                return(BadRequest());
            }

            if (!await _redisDb.HashExistsAsync(receiverAddress, guidString))
            {
                return(NotFound());
            }


            var mail = JsonConvert.DeserializeObject <ReceivedMail>(
                await _redisDb.HashGetAsync(receiverAddress, guidString));

            if (!mail.HasAttachements)
            {
                return(Ok(false));
            }

            foreach (var mailAttachement in mail.Attachements)
            {
                //todo query mail attachment, hash and compare with given attachment hash
            }

            return(Ok(true));
        }
        public async Task <JobModel> ReadAsync(string databaseKey, string jobId)
        {
            var data = await _redis.HashGetAsync(databaseKey, jobId).ConfigureAwait(false);

            return(await Task.Run(() =>
                                  JsonConvert.DeserializeObject <JobModel>(data)).ConfigureAwait(false));
        }
Пример #5
0
        protected override IObservable <RedisValue> GetIdsSingle(IDatabaseAsync database, IIndexKey index, long start = 0, long stop = -1)
        {
            var hashKey = ((HashIndexKey)index).HashKey;

            return(Observable.Create <RedisValue>(
                       async observer =>
            {
                var result = await Link.Resilience.AsyncRetryPolicy
                             .ExecuteAsync(async() => await database.HashGetAsync(Link.GetIndexKey(index), hashKey).ConfigureAwait(false))
                             .ConfigureAwait(false);
                observer.OnNext(result);
                observer.OnCompleted();
            }));
        }
Пример #6
0
        public async Task <IDictionary <string, TIndexedValue> > GetAsync(IDatabaseAsync context,
                                                                          IEnumerable <string> indexedKeys)
        {
            var keys       = indexedKeys as string[] ?? indexedKeys.ToArray();
            var jsonValues = await context.HashGetAsync(_indexCollectionName, keys.ToHashKeys());

            var entries = new Dictionary <string, TIndexedValue>();

            for (var i = 0; i < keys.Count(); i++)
            {
                var jsonValue = jsonValues[i];
                entries[keys[i]] = !jsonValue.HasValue ? default(TIndexedValue) : _indexedValueReader(jsonValue);
            }
            return(entries);
        }
Пример #7
0
        public async Task <IActionResult> GetMail([FromRoute, EmailAddress, Required] string receiverAddress, [FromRoute] Guid?mailGuid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var guidString = mailGuid.HasValue ? mailGuid.Value.ToString() : "";

            if (await _redisDb.HashExistsAsync(receiverAddress, guidString))
            {
                var mail = JsonConvert.DeserializeObject <ReceivedMail>(
                    await _redisDb.HashGetAsync(receiverAddress, guidString));
                return(Ok(mail));
            }
            return(NotFound());
        }
        public async Task <PollSummary> GetPollSummary(string pollId, ContextPropagationToken token = null)
        {
            try
            {
                if (pollId == null || pollId == "")
                {
                    return(null);
                }

                var response = await _database.HashGetAsync(PollSummaryHashKey, pollId);

                if (!response.HasValue)
                {
                    CallOptions opts;
                    if (token != null)
                    {
                        opts = new CallOptions(propagationToken: token);
                    }
                    else
                    {
                        opts = new CallOptions(deadline: DateTime.UtcNow.AddSeconds(1), cancellationToken: (new CancellationTokenSource(2000)).Token);
                    }
                    var pollsResponse = await _recordClient.GetPollsAsync(new Empty(), opts);

                    if (pollsResponse.Error)
                    {
                        _logger.LogWarning("Error response from record service while fetching polls for not found poll");
                        return(null);
                    }

                    var poll = pollsResponse.Polls.FirstOrDefault(x => x.Id == pollId);
                    if (poll == null)
                    {
                        return(null);
                    }
                    return(DefaultPollSummary(poll));
                }
                return(PollSummary.Parser.ParseFrom(response));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error while getting summary");
                return(null);
            }
        }
        private static async Task UpdateRowCacheInRedis(IDatabaseAsync db, RootIndexRow row)
        {
            var redisSetKey           = GetRedisKeyForColumn(row.ColumnName);
            var redisFilesToValuesKey = GetRedisFilesToValuesKeyForColumn(row.ColumnName);
            var redisValuesToFilesKey = GetRedisValuesToFilesKeyForColumn(row.ColumnName);
            var currentMaxValue       = await db.HashGetAsync(redisFilesToValuesKey, row.FileName);

            if (currentMaxValue != default)
            {
                await db.HashDeleteAsync(redisValuesToFilesKey, currentMaxValue);

                await db.SortedSetRemoveAsync(redisSetKey, currentMaxValue);
            }

            await db.HashSetAsync(redisValuesToFilesKey, row.FileName, row.Max);

            await db.HashSetAsync(redisValuesToFilesKey, row.Max, row.FileName);

            await db.SortedSetAddAsync(redisSetKey, row.Max, 0);
        }
Пример #10
0
 public async ValueTask <string?> HashGetAsync(string key, string field)
 {
     return(await _database.HashGetAsync(key, field));
 }
Пример #11
0
        public async Task <IActionResult> GetStatisticsCurrentValueByRcc()
        {
            JObject row_j = null;

            try
            {
                IQueryable <IGrouping <int, int> > idsGroup = GetRccCodeGroup();
                JArray        result     = new JArray();
                List <double> total_socs = new List <double>();
                foreach (IGrouping <int, int> row in idsGroup)
                {
                    double        total_energy_power       = 0;
                    double        total_actPwr_charging    = 0;
                    double        total_actPwr_discharging = 0;
                    List <double> socs        = new List <double>();
                    List <double> sohs        = new List <double>();
                    JObject       weather_obj = null;
                    foreach (int SiteId in row)
                    {
                        if (weather_obj == null)
                        {
                            weather_obj = await CommonFactory.RetriveWeather(SiteId, _redisDb);
                        }
                        // PV
                        string target_redis_key = CommonFactory.CreateRedisKey(SiteId, 4, "PV*");
                        var    redis_keys       = CommonFactory.SearchKeys(_redisConn, target_redis_key);
                        foreach (RedisKey pv_key in redis_keys)
                        {
                            double TotalActivePower = (double)await _redisDb.HashGetAsync(pv_key, "TotalActivePower");

                            total_energy_power += TotalActivePower;
                        }

                        // PCS
                        target_redis_key = CommonFactory.CreateRedisKey(SiteId, 1, "PCS*");
                        redis_keys       = CommonFactory.SearchKeys(_redisConn, target_redis_key);
                        foreach (RedisKey key in redis_keys)
                        {
                            double TotalActivePower = (double)await _redisDb.HashGetAsync(key, "actPwrKw");

                            if (TotalActivePower > 0)
                            {
                                total_actPwr_discharging += TotalActivePower;
                            }
                            else
                            {
                                total_actPwr_charging += TotalActivePower;
                            }
                        }

                        // BMS
                        target_redis_key = CommonFactory.CreateRedisKey(SiteId, 2, "BMS*");
                        redis_keys       = CommonFactory.SearchKeys(_redisConn, target_redis_key);
                        foreach (RedisKey key in redis_keys)
                        {
                            double soc = (double)await _redisDb.HashGetAsync(key, "bms_soc");

                            socs.Add(soc);
                            total_socs.Add(soc);
                            double soh = (double)await _redisDb.HashGetAsync(key, "bms_soh");

                            sohs.Add(soh);
                        }
                    }

                    row_j = new JObject();
                    row_j.Add("rcc", row.Key);
                    row_j.Add("total_pvpower", total_energy_power);
                    row_j.Add("total_charging", Math.Abs(total_actPwr_charging));
                    row_j.Add("total_discharging", total_actPwr_discharging);
                    row_j.Add("average_soc", socs.Count() > 0 ? socs.Average() : 0);
                    row_j.Add("average_soh", sohs.Count() > 0 ? sohs.Average() : 0);
                    row_j.Add("total_count", row.Count());
                    row_j.Add("weather", weather_obj);
                    result.Add(row_j);
                }

                JObject center_weather = await CommonFactory.RetriveWeather(0, _redisDb);

                return(Ok(new { group = result, total_average_soc = total_socs.Average(), total_event_count = 0, controlcenter_weather = center_weather }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex));
            }
        }
Пример #12
0
        public async Task <TIndexedValue> GetAsync(IDatabaseAsync context, string indexedKey)
        {
            var jsonValue = await context.HashGetAsync(_indexCollectionName, indexedKey);

            return(!jsonValue.HasValue ? default(TIndexedValue) : _indexedValueReader(jsonValue));
        }
        public async Task <IActionResult> getcurrenteventstatus(int siteId, string deviceName, int index)
        {
            try
            {
                int deviceType = 1;
                if (deviceName.ToUpper() == "PCS")
                {
                    deviceType = 1;
                }
                else if (deviceName.ToUpper() == "BMS")
                {
                    deviceType = 2;
                }
                else if (deviceName.ToUpper() == "PV")
                {
                    deviceType = 3;
                }
                else
                {
                    throw new ArgumentException("존재하지 않는 설비명");
                }
                JArray             result    = new JArray();
                VwContractorsiteEF site_info = await _accountContext.VwContractorsites.FindAsync(siteId);

                if (site_info == null)
                {
                    return(BadRequest());
                }


                using (var session = peiuGridDataContext.SessionFactory.OpenSession())
                {
                    var map_row = await session.CreateCriteria <PEIU.Events.Alarm.ModbusDiMap>()
                                  .Add(Restrictions.Eq("FactoryCode", site_info.DeviceGroupCode) && Restrictions.Eq("DeviceType", deviceType))
                                  .ListAsync <PEIU.Events.Alarm.ModbusDiMap>();

                    //map_row = await session.CreateCriteria<PEIU.Events.Alarm.ModbusDiMap>().ListAsync<PEIU.Events.Alarm.ModbusDiMap>();
                    foreach (PEIU.Events.Alarm.ModbusDiMap map in map_row)
                    {
                        JObject row = new JObject();
                        row.Add("code", map.EventCode);

                        row.Add("name", map.Name);
                        row.Add("category", map.DeviceType);
                        row.Add("level", map.Level);


                        string redisKey = $"SID{siteId}.DI.{deviceType}.{index}";
                        if (await db.HashExistsAsync(redisKey, map.EventCode))
                        {
                            string status = await db.HashGetAsync(redisKey, map.EventCode);

                            row.Add("status", status);
                        }
                        else
                        {
                            await db.HashSetAsync(redisKey, map.EventCode, bool.FalseString);

                            row.Add("status", bool.FalseString);
                        }

                        result.Add(row);
                    }
                }
                return(Ok(result));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }