Example #1
0
        private void TestServer(object obj)
        {
            SCLServer self  = (SCLServer)obj;
            IedModel  model = new IedModel("bubak");

            LogicalDevice ldevice1 = new LogicalDevice("strasidlo", model);

            LogicalNode lln0 = new LogicalNode("LLN0", ldevice1);

            DataObject lln0_mod    = CDCFactory.CDC_ENG("Mod", lln0, CDCOptions.NONE);
            DataObject lln0_health = CDCFactory.CDC_ENG("Health", lln0, CDCOptions.NONE);

            SettingGroupControlBlock sgcb = new SettingGroupControlBlock(lln0, 1, 1);

            /* Add a temperature sensor LN */
            LogicalNode ttmp1       = new LogicalNode("TTMP1", ldevice1);
            DataObject  ttmp1_tmpsv = CDCFactory.CDC_SAV("TmpSv", ttmp1, 0, false);

            DataAttribute temperatureValue     = ttmp1_tmpsv.GetChild_DataAttribute("instMag.f");
            DataAttribute temperatureTimestamp = ttmp1_tmpsv.GetChild_DataAttribute("t");

            IEC61850.Server.DataSet dataSet = new IEC61850.Server.DataSet("events", lln0);
            DataSetEntry            dse     = new DataSetEntry(dataSet, "TTMP1$MX$TmpSv$instMag$f", -1, null);

            IEC61850.Common.ReportOptions rptOptions = IEC61850.Common.ReportOptions.SEQ_NUM | IEC61850.Common.ReportOptions.TIME_STAMP | IEC61850.Common.ReportOptions.REASON_FOR_INCLUSION;

            IEC61850.Server.ReportControlBlock rcb1 = new IEC61850.Server.ReportControlBlock("events01", lln0, "events01", false, null, 1, IEC61850.Common.TriggerOptions.DATA_CHANGED, rptOptions, 50, 0);
            IEC61850.Server.ReportControlBlock rcb2 = new IEC61850.Server.ReportControlBlock("events02", lln0, "events02", true, null, 1, IEC61850.Common.TriggerOptions.DATA_CHANGED | IEC61850.Common.TriggerOptions.GI, rptOptions, 50, 0);

            IedServer server = new IedServer(model);

            server.Start(tcpPort);

            logger.LogInfo(String.Format("SCL Server Started at port 102!!!"));

            float val = 0.0f;

            while (_run)
            {
                server.LockDataModel();
                temperatureValue.MmsValue.SetFloat(val);
                temperatureTimestamp.MmsValue.SetUtcTimeMs(Util.GetTimeInMs());
                server.UnlockDataModel();

                val += 0.1f;

                int waitres = WaitHandle.WaitAny(_waitHandles, 500);
                switch (waitres)
                {
                case 0:         // endthread
                    self._run = false;
                    break;

                case WaitHandle.WaitTimeout:
                    break;
                }
            }
            logger.LogInfo(String.Format("SCL Server Finished!!!"));
        }
Example #2
0
 void createVL(NodeVL vl, LogicalNode ln)
 {
     IEC61850.Server.DataSet dataSet = new IEC61850.Server.DataSet(vl.Name, ln);
     vl.SCLServerModelObject = dataSet;
     foreach (NodeVLM vlm in vl.GetChildNodes())
     {
         DataSetEntry dse = new DataSetEntry(dataSet, vlm.SCL_ServerLink, -1, null);
         vlm.SCLServerModelObject = dse;
     }
 }
Example #3
0
        /// <summary>
        /// 新規にデータセットエントリを追加する
        /// </summary>
        public void AddEntry(DataSet dataSet, long dataTypeId, long dataId, bool isCreate)
        {
            DataSetEntry entry = new DataSetEntry()
            {
                DataTypeId = dataTypeId,
                DataId     = dataId
            };

            if (isCreate)
            {
                entry.DataSet = dataSet;
            }
            else
            {
                entry.DataSetId = dataSet.Id;
            }
            AddModel <DataSetEntry>(entry);
        }
Example #4
0
        public static AzureSearchDoc ToAzureSearchDoc(this DataSetEntry dsEntry)
        {
            var doc = new AzureSearchDoc()
            {
                Id           = dsEntry.Id,
                Title        = dsEntry.Title,
                ThumbnailUrl = dsEntry.ThumbnailUrl,
                Description  = null,
                Category     = dsEntry.Category,
                EntryType    = dsEntry.EntryType.ToString(),
                FruitionTime = dsEntry.FruitionTime,
                Language     = dsEntry.Language,
                SourceUrl    = dsEntry.SourceUrl,
            };

            foreach (var tag in dsEntry.Tags)
            {
                doc.Tags.Add(tag.Name);
            }
            return(doc);
        }
Example #5
0
        public static DataSetEntry MapToDataSetEntry(this FeedItem feedItem, DataSetEntryType entryType, IList <TextAnalysisResult> textAnalysisResult = null, IList <ImageAnalysisResult> imageAnalysisResult = null, IList <VideoAnalysisResult> videoAnalysisResult = null)
        {
            var dsEntry = new DataSetEntry();

            dsEntry.EntryType    = entryType;
            dsEntry.SourceUrl    = feedItem.Link;
            dsEntry.FruitionTime = 0;
            dsEntry.Title        = feedItem.Title;
            //dsEntry.ThumbnailUrl = feedItem.ThumbnailUrl;

            double maxLanguageScore  = 0.0;
            double maxSentimentScore = 0.0;

            if (textAnalysisResult != null)
            {
                foreach (var textAnalysis in textAnalysisResult)
                {
                    if (textAnalysis == null)
                    {
                        continue;
                    }

                    // Set the entry language to the most confident detected language score
                    if (textAnalysis.DetectedLanguageScore > maxLanguageScore)
                    {
                        maxLanguageScore = textAnalysis.DetectedLanguageScore;
                        dsEntry.Language = textAnalysis.DetectedLanguage;
                    }

                    // Set the entry sentiment to the most confident detected sentiment score
                    if (textAnalysis.SentimentScore > maxSentimentScore)
                    {
                        maxSentimentScore      = textAnalysis.SentimentScore;
                        dsEntry.SentimentScore = textAnalysis.SentimentScore;
                    }

                    // Retrieve and combine all detected tags
                    foreach (var keyPhrase in textAnalysis.KeyPhrases)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = keyPhrase, Score = 0.0
                        });
                    }

                    // Set the total fruition time to the sum of all text reading times
                    dsEntry.FruitionTime += textAnalysis.ReadingTimeInMinutes;
                }
            }

            if (imageAnalysisResult != null)
            {
                dsEntry.ImagesCount = imageAnalysisResult.Count;

                double maxRacyScore  = 0.0;
                double maxAdultScore = 0.0;
                foreach (var imageAnalysis in imageAnalysisResult)
                {
                    if (imageAnalysis == null)
                    {
                        continue;
                    }

                    // Retrieve and combine all detected categories
                    foreach (var category in imageAnalysis.Categories)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = category.Text, Score = category.Score
                        });
                    }

                    // Set the entry racy score to the most confident detected racy score
                    if (imageAnalysis.AdultContent.RacyScore > maxRacyScore)
                    {
                        maxRacyScore             = imageAnalysis.AdultContent.RacyScore;
                        dsEntry.RacyContentScore = imageAnalysis.AdultContent.RacyScore;
                    }

                    // Set the entry adult score to the most confident detected adult score
                    if (imageAnalysis.AdultContent.AdultScore > maxAdultScore)
                    {
                        maxAdultScore             = imageAnalysis.AdultContent.AdultScore;
                        dsEntry.AdultContentScore = imageAnalysis.AdultContent.AdultScore;
                    }

                    // Sum the number of people found in all images
                    dsEntry.PeopleTotalCount  += imageAnalysis.Faces.Count;
                    dsEntry.PeopleFemaleCount += imageAnalysis.Faces.Where(f => f.Gender == Gender.Female).Count();
                    dsEntry.PeopleMaleCount   += imageAnalysis.Faces.Where(f => f.Gender == Gender.Male).Count();

                    // Set the total fruition time to the sum of all image watching times
                    dsEntry.FruitionTime += imageAnalysis.WatchingTimeInMinutes;

                    // Ignore colors. How to use them?
                    //dsEntry.IsBlackAndWhiteImage = imageAnalysis.Colors.IsBWImg;
                    //dsEntry.DominantBackgroundColor = imageAnalysis.Colors.DominantColorBackground;
                    //dsEntry.DominantForegroundColor = imageAnalysis.Colors.DominantColorForeground;
                    //dsEntry.AccentColor = imageAnalysis.Colors.AccentColor;
                }
            }

            if (videoAnalysisResult != null)
            {
                dsEntry.VideosCount = videoAnalysisResult.Count;

                foreach (var videoAnalysis in videoAnalysisResult)
                {
                    if (videoAnalysis == null)
                    {
                        continue;
                    }

                    // Set the total fruition time to the sum of all video length times
                    dsEntry.FruitionTime += videoAnalysis.LengthInMinutes;

                    // Sum the number of people found in all videos
                    //dsEntry.PeopleTotalCount += videoAnalysis.Faces.Count;
                    //dsEntry.PeopleFemaleCount += videoAnalysis.Faces.Where(f => f.Gender == Gender.Female).Count();
                    //dsEntry.PeopleMaleCount += videoAnalysis.Faces.Where(f => f.Gender == Gender.Male).Count();
                }
            }

            return(dsEntry);
        }
Example #6
0
        public static DataSetEntry MapToDataSetEntry(this Tweet tweet, DataSetEntryType entryType, IList <TextAnalysisResult> textAnalysisResult = null, IList <ImageAnalysisResult> imageAnalysisResult = null, IList <VideoAnalysisResult> videoAnalysisResult = null)
        {
            var dsEntry = new DataSetEntry
            {
                EntryType    = entryType,
                SourceUrl    = tweet.Url,
                Title        = tweet.Content,
                ThumbnailUrl = tweet.MediaEntities[TweetEntityMediaType.Image].FirstOrDefault()
            };

            double maxLanguageScore  = 0.0;
            double maxSentimentScore = 0.0;
            double maxRacyScore      = 0.0;
            double maxAdultScore     = 0.0;

            if (textAnalysisResult != null)
            {
                foreach (var textAnalysis in textAnalysisResult)
                {
                    if (textAnalysis == null)
                    {
                        continue;
                    }

                    // Set the entry language to the most confident detected language score
                    if (textAnalysis.DetectedLanguageScore > maxLanguageScore)
                    {
                        maxLanguageScore = textAnalysis.DetectedLanguageScore;
                        dsEntry.Language = textAnalysis.DetectedLanguage;
                    }

                    // Set the entry sentiment to the most confident detected sentiment score
                    if (textAnalysis.SentimentScore > maxSentimentScore)
                    {
                        maxSentimentScore      = textAnalysis.SentimentScore;
                        dsEntry.SentimentScore = textAnalysis.SentimentScore;
                    }

                    // Retrieve and combine all detected tags
                    foreach (var keyPhrase in textAnalysis.KeyPhrases)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = keyPhrase, Score = 0.0
                        });
                    }

                    // Set the total fruition time to the sum of all text reading times
                    dsEntry.FruitionTime += textAnalysis.ReadingTimeInMinutes;
                }
            }

            if (imageAnalysisResult != null)
            {
                dsEntry.ImagesCount = imageAnalysisResult.Count;

                foreach (var imageAnalysis in imageAnalysisResult)
                {
                    if (imageAnalysis == null)
                    {
                        continue;
                    }

                    // Retrieve and combine all detected categories
                    foreach (var category in imageAnalysis.Categories)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = category.Text, Score = category.Score
                        });
                    }

                    // Set the entry racy score to the most confident detected racy score
                    if (imageAnalysis.AdultContent.RacyScore > maxRacyScore)
                    {
                        maxRacyScore             = imageAnalysis.AdultContent.RacyScore;
                        dsEntry.RacyContentScore = imageAnalysis.AdultContent.RacyScore;
                    }

                    // Set the entry adult score to the most confident detected adult score
                    if (imageAnalysis.AdultContent.AdultScore > maxAdultScore)
                    {
                        maxAdultScore             = imageAnalysis.AdultContent.AdultScore;
                        dsEntry.AdultContentScore = imageAnalysis.AdultContent.AdultScore;
                    }

                    // Sum the number of people found in all images
                    dsEntry.PeopleTotalCount  += imageAnalysis.Faces.Count;
                    dsEntry.PeopleFemaleCount += imageAnalysis.Faces.Where(f => f.Gender == Gender.Female).Count();
                    dsEntry.PeopleMaleCount   += imageAnalysis.Faces.Where(f => f.Gender == Gender.Male).Count();

                    // Set the total fruition time to the sum of all image watching times
                    dsEntry.FruitionTime += imageAnalysis.WatchingTimeInMinutes;

                    // Ignore colors. How to use them?
                    //dsEntry.IsBlackAndWhiteImage = imageAnalysis.Colors.IsBWImg;
                    //dsEntry.DominantBackgroundColor = imageAnalysis.Colors.DominantColorBackground;
                    //dsEntry.DominantForegroundColor = imageAnalysis.Colors.DominantColorForeground;
                    //dsEntry.AccentColor = imageAnalysis.Colors.AccentColor;
                }
            }

            if (videoAnalysisResult != null)
            {
                dsEntry.VideosCount = videoAnalysisResult.Count;

                double maxSentimentRatio = 0.0;
                foreach (var videoAnalysis in videoAnalysisResult)
                {
                    if (videoAnalysis == null)
                    {
                        continue;
                    }

                    // Retrieve and combine all detected annotations
                    foreach (var annotation in videoAnalysis.Annotations)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = annotation.Name, Score = 0.0
                        });
                    }

                    // Retrieve and combine all detected keywords
                    foreach (var topic in videoAnalysis.Topics)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = topic.Name, Score = 0.0
                        });
                    }

                    // Retrieve and combine all detected text
                    // NOTE: if Topics are detected, OCR text maybe redundant
                    foreach (var text in videoAnalysis.Text)
                    {
                        dsEntry.Tags.Add(new DataSetTag {
                            Name = text, Score = 0.0
                        });
                    }

                    // Set the total fruition time to the sum of all video length times
                    dsEntry.FruitionTime += videoAnalysis.LengthInMinutes;

                    // Sum the number of people found in all videos
                    dsEntry.PeopleTotalCount += videoAnalysis.Faces.Count;
                    // No info of gender in videos
                    //dsEntry.PeopleFemaleCount += videoAnalysis.Faces.Where(f => f.Gender == Gender.Female).Count();
                    //dsEntry.PeopleMaleCount += videoAnalysis.Faces.Where(f => f.Gender == Gender.Male).Count();

                    // Set the entry racy score to the most confident detected adult score
                    if (videoAnalysis.ContentModeration.AdultClassifierValue > maxAdultScore)
                    {
                        maxRacyScore = videoAnalysis.ContentModeration.AdultClassifierValue;
                        dsEntry.AdultContentScore = videoAnalysis.ContentModeration.AdultClassifierValue;
                    }

                    // Set the entry racy score to the most confident detected racy score
                    if (videoAnalysis.ContentModeration.RacyClassifierValue > maxRacyScore)
                    {
                        maxRacyScore             = videoAnalysis.ContentModeration.RacyClassifierValue;
                        dsEntry.RacyContentScore = videoAnalysis.ContentModeration.RacyClassifierValue;
                    }

                    // Set the entry sentiment score to the highest ratio
                    foreach (var sentiment in videoAnalysis.Sentiments)
                    {
                        if (sentiment.SeenDurationRatio > maxSentimentRatio)
                        {
                            maxSentimentRatio = sentiment.SeenDurationRatio;

                            var score = sentiment.SentimentKey == "Neutral" ? 0.5 : sentiment.SentimentKey == "Negative" ? 0.0 : 1.0;
                            if (score > maxSentimentScore)
                            {
                                dsEntry.SentimentScore = score;
                            }
                        }
                    }
                }
            }

            return(dsEntry);
        }