Example #1
0
        public async Task <List <Responses.Indicator> > GetAllIndicators(string userId, IndicatorType indicatorType)
        {
            // Get user
            var user = await _userRepository.GetSingle(userId);

            // Check if it exists
            if (user == null)
            {
                throw new NotFoundException(UserMessage.UserNotFound);
            }

            // Get all indicators
            var indicators = await _indicatorRepository.GetAll(IndicatorExpression.IndicatorFilter(indicatorType, null, userId));

            // Get all indicator dependencies
            var indicatorDependencies = await _indicatorDependencyRepository.GetAll();

            // Build indicator dependencies
            IndicatorBuilder.BuildDependencies(indicators, indicatorDependencies);

            // Response
            var response = _mapper.Map <List <Responses.Indicator> >(indicators);

            // Return
            return(response);
        }
        public async Task <Responses.Indicator> AddIndicator(AddIndicator request)
        {
            // Get indicator
            var indicator = await _mainDbContext.Indicators
                            .Include(x => x.Dependencies)
                            .FirstOrDefaultAsync(x => x.IndicatorId == request.IndicatorId);

            // Throw ConflictException if it exists
            if (indicator != null)
            {
                throw new ConflictException(IndicatorMessage.IndicatorWithSameIdAlreadyExists);
            }

            // Check uniqueness
            indicator = await _mainDbContext.Indicators
                        .Include(x => x.Dependencies)
                        .FirstOrDefaultAsync(IndicatorExpression.IndicatorUnique(request.Name));

            // Throw ConflictException if it exists
            if (indicator != null)
            {
                throw new ConflictException(IndicatorMessage.IndicatorWithSameNameAlreadyExists);
            }

            // Get dependencies
            var dependencies = await GetDependencies(request.Dependencies);

            // Build dependency level
            var dependencyLevel = IndicatorBuilder.BuildDependencyLevel(dependencies);

            // Build new indicator dependencies
            var indicatorDependencies = IndicatorDependencyBuilder.BuildIndicatorDependencies(request.IndicatorId, dependencies);

            // Create
            indicator = new Indicator(
                request.IndicatorId,
                request.IndicatorType,
                request.UserId,
                request.Name,
                request.Description,
                request.Formula,
                indicatorDependencies,
                dependencyLevel,
                DateTime.Now);

            // Add
            _mainDbContext.Indicators.Add(indicator);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Log into Splunk
            _logger.LogSplunkInformation(request);

            // Response
            var response = _mapper.Map <Responses.Indicator>(indicator);

            // Return
            return(response);
        }
        public async Task <List <Indicator> > UpdateDependencyLevels()
        {
            // Start watch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Get all indicators
            var indicators = await _mainDbContext.Indicators.ToListAsync();

            // Get all indicators dependencies
            var indicatorDependencies = await _mainDbContext.IndicatorDependencies.ToListAsync();

            // Build dependency levels
            IndicatorBuilder.BuildDependencyLevels(indicators, indicatorDependencies);

            // Update
            _mainDbContext.Indicators.UpdateRange(indicators);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Build max dependency level
            var maxDependencyLevel = IndicatorBuilder.BuildMaxDependencyLevel(indicators);

            // Stop watch
            stopwatch.Stop();

            // Log
            _logger.LogInformation("{@Event}, {@MaxLevel}, {@ExecutionTime}", "DependenciesLevelsUpdated", maxDependencyLevel, stopwatch.Elapsed.TotalSeconds);

            // Return
            return(indicators);
        }
        public async Task <List <Indicator> > GetDependencies(List <string> dependencyIds)
        {
            var dependencies = new List <Indicator>();

            foreach (var dependencyId in dependencyIds)
            {
                var userId      = IndicatorBuilder.BuildUserId(dependencyId);
                var indicatorId = IndicatorBuilder.BuildIndicatorId(dependencyId);

                // Get indicator
                var dependency = await _mainDbContext.Indicators.FindAsync(userId, indicatorId);

                // Throw NotFound if it does not exist
                if (dependency == null)
                {
                    throw new NotFoundException(string.Format(IndicatorDependencyMessage.IndicatorDependencyNotFound, dependencyId));
                }

                // Add
                dependencies.Add(dependency);
            }

            // Return
            return(dependencies);
        }
Example #5
0
        /// <summary>
        /// Returns the metadata text from database
        /// </summary>
        /// <param name="elementNid"></param>
        /// <returns></returns>
        public override string GetMetadataTextFrmDB(int elementNid)
        {
            string             RetVal     = string.Empty;
            string             ElementGID = string.Empty;
            IndicatorBuilder   Indicators;
            DI7MetaDataBuilder MDBuilder = null;

            try
            {
                Indicators = new IndicatorBuilder(this.DBConnection, this.DBQueries);
                ElementGID = Indicators.GetIndicatorInfo(FilterFieldType.NId, elementNid.ToString(), FieldSelection.Light).GID;

                // get xml file from SDMX library
                RetVal = DevInfo.Lib.DI_LibSDMX.SDMXUtility.Get_MetadataReport(DI_LibSDMX.SDMXSchemaType.Two_One, ElementGID, DevInfo.Lib.DI_LibSDMX.MetadataTypes.Indicator, "MDAgency", this.DBQueries.LanguageCode.Replace("_", ""), this.DBConnection, this.DBQueries).InnerXml;

                MDBuilder = new DI7MetaDataBuilder(this.DBConnection, this.DBQueries);
                RetVal    = MDBuilder.GetMetadataReportWCategoryName(RetVal, MetadataElementType.Indicator).InnerXml;
            }
            catch (Exception)
            {
                RetVal = string.Empty;
            }

            return(RetVal);
        }
 public CenteredRefresher(
     List <Widget> children,
     IndicatorBuilder headerBuilder = null,
     IndicatorBuilder footerBuilder = null,
     Config headerConfig            = null,
     Config footerConfig            = null,
     bool enablePullUp             = DefaultConstants.default_enablePullUp,
     bool enablePullDown           = DefaultConstants.default_enablePullDown,
     bool enableOverScroll         = DefaultConstants.default_enableOverScroll,
     OnRefresh onRefresh           = null,
     OnOffsetChange onOffsetChange = null,
     RefreshController controller  = null,
     NotificationListenerCallback <ScrollNotification> onNotification = null,
     Key key         = null,
     int centerIndex = 0
     ) : base(key)
 {
     this.children      = children;
     this.headerBuilder =
         headerBuilder ?? ((context, mode) => new SmartRefreshHeader(mode, RefreshHeaderType.other));
     this.footerBuilder    = footerBuilder ?? ((context, mode) => new SmartRefreshFooter(mode));
     this.headerConfig     = headerConfig ?? new RefreshConfig();
     this.footerConfig     = footerConfig ?? new LoadConfig(triggerDistance: 0);
     this.enablePullUp     = enablePullUp;
     this.enablePullDown   = enablePullDown;
     this.enableOverScroll = enableOverScroll;
     this.onRefresh        = onRefresh;
     this.onOffsetChange   = onOffsetChange;
     this.controller       = controller ?? new RefreshController();
     this.onNotification   = onNotification;
     this.centerIndex      = centerIndex;
 }
 public SmartRefresher(
     ScrollView child,
     float initialOffset            = 0f,
     IndicatorBuilder headerBuilder = null,
     IndicatorBuilder footerBuilder = null,
     Config headerConfig            = null,
     Config footerConfig            = null,
     bool enablePullUp             = DefaultConstants.default_enablePullUp,
     bool enablePullDown           = DefaultConstants.default_enablePullDown,
     bool enableOverScroll         = DefaultConstants.default_enableOverScroll,
     OnRefresh onRefresh           = null,
     OnOffsetChange onOffsetChange = null,
     RefreshController controller  = null,
     NotificationListenerCallback <ScrollNotification> onNotification = null,
     Key key = null
     ) : base(key)
 {
     this.child         = child;
     this.initialOffset = initialOffset;
     this.headerBuilder =
         headerBuilder ?? ((context, mode) => new SmartRefreshHeader(mode, RefreshHeaderType.other));
     this.footerBuilder    = footerBuilder ?? ((context, mode) => new SmartRefreshFooter(mode));
     this.headerConfig     = headerConfig ?? new RefreshConfig();
     this.footerConfig     = footerConfig ?? new LoadConfig(triggerDistance: 0);
     this.enablePullUp     = enablePullUp;
     this.enablePullDown   = enablePullDown;
     this.enableOverScroll = enableOverScroll;
     this.onRefresh        = onRefresh;
     this.onOffsetChange   = onOffsetChange;
     this.controller       = controller ?? new RefreshController();
     this.onNotification   = onNotification;
 }
Example #8
0
 public LoadWrapper(
     bool up,
     ValueNotifier <int> modeListener = null,
     bool autoLoad            = true,
     IndicatorBuilder builder = null,
     float triggerDistance    = 0,
     Key key = null
     ) : base(modeListener, up, builder, triggerDistance, key)
 {
     this.autoLoad = autoLoad;
 }
        public void Test_PriceChange24Hrs()
        {
            // Arrange
            var indicatorId = "price-change-24hrs";
            var allIndicatorDependencies = FakeIndicatorDependencies.GetFakeIndicatorDependencies();

            // Act
            var dependencyLevel = IndicatorBuilder.BuildDependencyLevel(indicatorId, allIndicatorDependencies);

            // Assert
            Assert.AreEqual(1, dependencyLevel);
        }
        public void Test_Hype()
        {
            // Arrange
            var indicatorId = "hype";
            var allIndicatorDependencies = FakeIndicatorDependencies.GetFakeIndicatorDependencies();

            // Act
            var dependencyLevel = IndicatorBuilder.BuildDependencyLevel(indicatorId, allIndicatorDependencies);

            // Assert
            Assert.AreEqual(2, dependencyLevel);
        }
Example #11
0
        public void Test_BuildDependencyLevel_Price()
        {
            // Arrange
            var indicatorId = "master.PRICE";
            var allIndicatorDependencies = FakeIndicatorDependency.GetFakeIndicatorDependencies();

            // Act
            var dependencyLevel = IndicatorBuilder.BuildDependencyLevel(indicatorId, allIndicatorDependencies);

            // Assert
            Assert.AreEqual(0, dependencyLevel);
        }
Example #12
0
 protected Wrapper(
     ValueNotifier <int> modeListener,
     bool up,
     IndicatorBuilder builder = null,
     float triggerDistance    = 0,
     Key key = null
     ) : base(key)
 {
     this.modeListener    = modeListener;
     this.up              = up;
     this.builder         = builder;
     this.triggerDistance = triggerDistance;
 }
Example #13
0
        //private int ImportIndicator(DataRow row)
        //{
        //    int RetVal = -1;

        //    IndicatorInfo IndicatorRecord;
        //    IndicatorBuilder IndicatorBuilderObj;

        //    IndicatorRecord = this.GetIndicatorInfo(row);
        //    IndicatorBuilderObj = new IndicatorBuilder(this._TargetDBConnection, this._TargetDBQueries);
        //    RetVal = IndicatorBuilderObj.ImportIndicator(IndicatorRecord, IndicatorRecord.Nid, this.SourceDBQueries, this.SourceDBConnection);

        //    return RetVal;
        //}

        //private int ImportUnit(DataRow row)
        //{
        //    int RetVal = -1;

        //    UnitInfo UnitRecord;
        //    UnitBuilder UnitBuilderObj;

        //    UnitRecord = this.GetUnitInfo(row);

        //    UnitBuilderObj = new UnitBuilder(this._TargetDBConnection, this._TargetDBQueries);
        //    RetVal = UnitBuilderObj.ImportUnit(UnitRecord, UnitRecord.Nid, this.SourceDBQueries, this.SourceDBConnection);

        //    return RetVal;
        //}

        //private int ImportSubgroupVal(DataRow row)
        //{
        //    int RetVal = -1;

        //    DI6SubgroupValBuilder SubgroupValBuilderObj = new DI6SubgroupValBuilder(this._TargetDBConnection, this._TargetDBQueries);

        //    //import into target database
        //    RetVal = SubgroupValBuilderObj.ImportSubgroupVal(Convert.ToInt32(row[SubgroupVals.SubgroupValNId]), this.SourceDBQueries, this.SourceDBConnection);

        //    return RetVal;
        //}

        //private void ImportIUS(List<string> selectedNids, bool allSelected)
        //{
        //    int ProgressBarValue = 1;
        //    int IndicatorNId = -1;
        //    int UnitNId = -1;
        //    int SGValNId = -1;
        //    int MinValue=0;
        //    int MaxValue=0;

        //    DataRow[] Rows;
        //    DataTable TempTable;

        //    List<string> ImportedIndicatorNIDs = new List<string>();
        //    List<string> ImportedUnitNIDs = new List<string>();
        //    List<string> ImportedSGNIDs = new List<string>();

        //    IUSBuilder IusBuilderObj ;

        //    if (this.ShowIUS)
        //    {
        //        // Get selected rows
        //        if (allSelected)
        //        {
        //            Rows = this.SourceTable.Select("1=1");
        //        }
        //        else
        //        {
        //            Rows = this.SourceTable.Select(this.TagValueColumnName + " IN ( " + string.Join(",", selectedNids.ToArray()) + ")");
        //        }

        //        foreach (DataRow Row in Rows)
        //        {
        //            try
        //            {
        //                //import Indicator
        //                IndicatorNId = Convert.ToInt32(Row[Indicator.IndicatorNId]);
        //                if (!ImportedIndicatorNIDs.Contains(IndicatorNId.ToString()))
        //                {
        //                    ImportedIndicatorNIDs.Add(IndicatorNId.ToString());
        //                    IndicatorNId = this.ImportIndicator(Row);
        //                }


        //                    // import unit
        //                UnitNId = Convert.ToInt32(Row[Unit.UnitNId]);
        //                if (!ImportedIndicatorNIDs.Contains(UnitNId.ToString()))
        //                {
        //                   ImportedUnitNIDs.Add(UnitNId.ToString());
        //                    UnitNId =  this.ImportUnit(Row);
        //                }

        //                // import subgroupval
        //                SGValNId=Convert.ToInt32(Row[SubgroupVals.SubgroupValNId]);
        //                if (!ImportedSGNIDs.Contains(SGValNId.ToString()))
        //                {
        //                    ImportedSGNIDs.Add(SGValNId.ToString());
        //                    SGValNId = this.ImportSubgroupVal(Row);
        //                }

        //                //import IUS
        //                if (IndicatorNId > 0 && UnitNId > 0 && SGValNId > 0)
        //                {
        //                    //if(Convert.ToString(Row[Indicator_Unit_Subgroup.MaxValue]).Length>0)
        //                    //{
        //                    //MaxValue=   Convert.ToInt32(Row[Indicator_Unit_Subgroup.MaxValue]);
        //                    //}
        //                    //else
        //                    //{
        //                    //    MaxValue=0;
        //                    //}

        //                    //if(Convert.ToString(Row[Indicator_Unit_Subgroup.MinValue]).Length>0)
        //                    //{
        //                    //    MinValue= Convert.ToInt32(Row[Indicator_Unit_Subgroup.MinValue]);
        //                    //}
        //                    //else
        //                    //{
        //                    //    MinValue=0;
        //                    //}


        //                    IusBuilderObj = new IUSBuilder( this._TargetDBConnection, this._TargetDBQueries);

        //                    IusBuilderObj.ImportIUS(IndicatorNId, UnitNId, SGValNId,                                                    MinValue, MaxValue , this.SourceDBQueries, this.SourceDBConnection);

        //                }

        //                if (this.ShowSector)
        //                {
        //                    this.ImportSector(Row);
        //                }
        //            }
        //            catch (Exception)
        //            {

        //                throw;
        //            }
        //            this.RaiseIncrementProgessBarEvent(ProgressBarValue);
        //            ProgressBarValue++;
        //        }
        //    }
        //}

        /// <summary>
        /// Imports records from source database to target database/template
        /// </summary>
        /// <param name="selectedNids"></param>
        /// <param name="allSelected">Set true to import all records</param>
        public override void ImportValues(List <string> selectedNids, bool allSelected)
        {
            DataRow                    Row;
            IndicatorInfo              IndicatorRecord            = null;
            IndicatorBuilder           IndicatorBuilderObj        = null;
            DI7MetadataCategoryBuilder MetadataCategoryBuilderObj = null;
            int ProgressBarValue = 1;

            // import indicator metadata categories
            MetadataCategoryBuilderObj = new DI7MetadataCategoryBuilder(this._TargetDBConnection, this._TargetDBQueries);
            MetadataCategoryBuilderObj.ImportAllMetadataCategories(this.SourceDBConnection, this.SourceDBQueries, MetadataElementType.Indicator);

            // import IUS or indicator
            foreach (string Nid in selectedNids)
            {
                try
                {
                    Row = this.SourceTable.Select(this.TagValueColumnName + "=" + Nid)[0];

                    if (this._ShowIUS)
                    {
                        this.ImportForIUS(Row);
                    }
                    else
                    {
                        //import indicator
                        IndicatorRecord     = this.GetIndicatorInfo(Row);
                        IndicatorBuilderObj = new IndicatorBuilder(this._TargetDBConnection, this._TargetDBQueries);
                        IndicatorBuilderObj.ImportIndicator(IndicatorRecord, Convert.ToInt32(Nid), this.SourceDBQueries, this.SourceDBConnection);

                        if (this._ShowSector)
                        {
                            this.ImportSector(Row);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
                this.RaiseIncrementProgessBarEvent(ProgressBarValue);
                ProgressBarValue++;
            }


            if (this._ShowIUS && this._ShowSector)
            {
                this.ImportSectors(selectedNids, allSelected);
            }
        }
Example #14
0
        public void Test_2()
        {
            // Arrange
            var values = new decimal?[] { 5, 1, 1, 1, -5 };

            // Act
            IndicatorBuilder.BuildHypes(values);

            // Assert
            Assert.AreEqual(true, values[0] >= 0);
            Assert.AreEqual(true, values[1] >= 0);
            Assert.AreEqual(true, values[2] >= 0);
            Assert.AreEqual(true, values[3] >= 0);
            Assert.AreEqual(true, values[4] == 0);
        }
Example #15
0
        public void Test_BuildHypes_3()
        {
            // Arrange
            var values = new decimal[] { 6, 1, 1, 1, 1 };

            // Act
            IndicatorBuilder.BuildHypes(values);

            // Assert
            Assert.AreEqual(true, values[0] >= 0);
            Assert.AreEqual(true, values[1] == 0);
            Assert.AreEqual(true, values[2] == 0);
            Assert.AreEqual(true, values[3] == 0);
            Assert.AreEqual(true, values[4] == 0);
        }
        public void Hype_6()
        {
            // Arrange
            var values = new decimal?[] { 50, 0, 0, 0, -50 };

            // Act
            IndicatorBuilder.BuildHypes(values);

            // Assert
            Assert.AreEqual(true, values[0] >= 0);
            Assert.AreEqual(true, values[1] == 0);
            Assert.AreEqual(true, values[2] == 0);
            Assert.AreEqual(true, values[3] == 0);
            Assert.AreEqual(true, values[4] == 0);
        }
Example #17
0
 public RefreshWrapper(
     bool up,
     ValueNotifier <int> modeListener = null,
     int completeDuration             = DefaultConstants.default_completeDuration,
     OnOffsetChange onOffsetChange    = null,
     float visibleRange       = DefaultConstants.default_VisibleRange,
     IndicatorBuilder builder = null,
     float triggerDistance    = 0,
     Key key = null
     ) : base(modeListener, up, builder, triggerDistance, key)
 {
     this.completeDuration = completeDuration;
     this.onOffsetChange   = onOffsetChange;
     this.visibleRange     = visibleRange;
 }
Example #18
0
 public SmartRefresher(
     ScrollView child,
     float initialOffset            = 0f,
     IndicatorBuilder headerBuilder = null,
     IndicatorBuilder footerBuilder = null,
     Config headerConfig            = null,
     Config footerConfig            = null,
     bool enablePullUp             = DefaultConstants.default_enablePullUp,
     bool enablePullDown           = DefaultConstants.default_enablePullDown,
     bool enableOverScroll         = DefaultConstants.default_enableOverScroll,
     bool reverse                  = false,
     OnRefresh onRefresh           = null,
     OnOffsetChange onOffsetChange = null,
     RefreshController controller  = null,
     NotificationListenerCallback <ScrollNotification> onNotification = null,
     bool hasBottomMargin = false,
     Key key = null
     ) : base(key)
 {
     this.child         = child;
     this.initialOffset = initialOffset;
     this.headerBuilder =
         headerBuilder ?? ((context, mode) => new SmartRefreshHeader(mode, RefreshHeaderType.other));
     this.footerBuilder = footerBuilder ?? ((context, mode) => new SmartRefreshFooter(
                                                mode: mode,
                                                hasBottomMargin
                                  ? EdgeInsets.only(0, 16, 0,
                                                    16 + CConstant.TabBarHeight +
                                                    MediaQuery.of(context: context).padding.bottom)
                                  : null
                                                ));
     this.headerConfig     = headerConfig ?? new RefreshConfig();
     this.footerConfig     = footerConfig ?? new LoadConfig(triggerDistance: 0);
     this.enablePullUp     = enablePullUp;
     this.enablePullDown   = enablePullDown;
     this.enableOverScroll = enableOverScroll;
     this.onRefresh        = onRefresh;
     this.onOffsetChange   = onOffsetChange;
     this.controller       = controller ?? new RefreshController();
     this.onNotification   = onNotification;
     this.reverse          = reverse;
 }
Example #19
0
        public async Task <List <Indicator> > UpdateIndicatorDependencies()
        {
            // Start watch
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            // Get all indicators
            var indicators = await _indicatorRepository.GetAll();

            // Get all indicator dependencies
            var indicatorDependencies = await _indicatorDependencyRepository.GetAll();

            // Build indicator dependencies
            IndicatorBuilder.BuildDependencies(indicators, indicatorDependencies);

            // Build dependency levels
            IndicatorBuilder.BuildDependencyLevels(indicators, indicatorDependencies);

            // Update
            _indicatorRepository.UpdateRange(indicators);

            // Save
            await _dbContext.SaveChangesAsync();

            // Build max dependency level
            var maxDependencyLevel = IndicatorBuilder.BuildMaxDependencyLevel(indicators);

            // Stop watch
            stopwatch.Stop();

            // Log into Splunk
            _logger.LogSplunkInformation("UpdateIndicatorDependencies", new
            {
                MaxLevel      = maxDependencyLevel,
                ExecutionTime = stopwatch.Elapsed.TotalSeconds
            });

            // Return
            return(indicators);
        }
Example #20
0
        protected virtual void initialize_point(ControlPoint pt)
        {
            SphereIndicator indicator = IndicatorBuilder.MakeSphereIndicator(
                pt.id, pt.name,
                fDimension.Scene(pt.sizeS / 2),
                () => { return(pt.currentFrameS); },
                () => { return(pt.color); },
                () => { return(true); }
                );

            Indicators.AddIndicator(indicator);
            indicator.RootGameObject.SetName(pt.name);

            pt.indicator = indicator;
            if (pt.layer != -1)
            {
                Indicators.SetLayer(indicator, pt.layer);
            }
            pt.initialized = true;
            OnPointInitialized(pt);
        }
        /// <summary>
        /// called on click-down
        /// </summary>
        override public void Begin(SceneObject so, Vector2d downPos, Ray3f downRay)
        {
            SORayHit hit;

            if (TargetSO.FindRayIntersection(downRay, out hit) == false)
            {
                return;
            }

            Vector3d scenePos = SceneTransforms.WorldToSceneP(this.Scene, hit.hitPos);

            CurrentHitPosS = new Frame3f(scenePos);

            float fObjectT = (CurrentHitPosS.Origin - ObjectFrameS.Origin).Dot(ObjectFrameS.Y);

            CurrentPlaneFrameS = ObjectFrameS.Translated(fObjectT, 1);

            if (have_set_plane == false)
            {
                sphereIndicator = IndicatorBuilder.MakeSphereIndicator(0, "hit_point",
                                                                       fDimension.Scene(sphere_indicator_size * 0.5),
                                                                       () => { return(CurrentHitPosS); },
                                                                       () => { return(Colorf.Orange); },
                                                                       () => { return(true); });
                Indicators.AddIndicator(sphereIndicator);
                sphereIndicator.RootGameObject.SetName("hit_point");

                planeIndicator = IndicatorBuilder.MakeSectionPlaneIndicator(1, "section_plane",
                                                                            fDimension.Scene(plane_indicator_width),
                                                                            () => { return(CurrentPlaneFrameS); },
                                                                            () => { return(new Colorf(Colorf.LightGreen, 0.5f)); },
                                                                            () => { return(true); });
                Indicators.AddIndicator(planeIndicator);
                planeIndicator.RootGameObject.SetName("section_plane");

                have_set_plane = true;
            }
        }
        public override void Setup()
        {
            StartPointID = AppendSurfacePoint("StartPoint", Colorf.Blue);
            EndPointID   = AppendSurfacePoint("EndPoint", Colorf.Green);

            //LineIndicator line = new LineIndicator() {
            //    LineWidth = fDimension.Scene(1.0f),
            //    SceneStartF = () => { return GizmoPoints[StartPointID].currentFrameS.Origin; },
            //    SceneEndF = () => { return GizmoPoints[EndPointID].currentFrameS.Origin; },
            //};
            //indicators.AddIndicator(line);
            //indicators.SetLayer(line, FPlatform.HUDOverlay);   // has to be hud overlay or it will be clipped by depth render

            Frame3f TargetFrameS = TargetSO.GetLocalFrame(CoordSpace.SceneCoords);

            TargetAxis = new Line3d(TargetFrameS.Origin, Vector3d.AxisY);

            SectionPlaneIndicator startPlane = IndicatorBuilder.MakeSectionPlaneIndicator(
                100, "startPlane",
                fDimension.Scene(plane_indicator_width),
                () => { return(new Frame3f(TargetAxis.ClosestPoint(GizmoPoints[StartPointID].currentFrameS.Origin))); },
                () => { return(new Colorf(Colorf.LightGreen, 0.5f)); },
                () => { return(true); }
                );

            Indicators.AddIndicator(startPlane);

            SectionPlaneIndicator endPlane = IndicatorBuilder.MakeSectionPlaneIndicator(
                101, "endPlane",
                fDimension.Scene(plane_indicator_width),
                () => { return(new Frame3f(TargetAxis.ClosestPoint(GizmoPoints[EndPointID].currentFrameS.Origin))); },
                () => { return(new Colorf(Colorf.LightGreen, 0.5f)); },
                () => { return(true); }
                );

            Indicators.AddIndicator(endPlane);
        }
Example #23
0
        public override void Import(string selectedGIds)
        {
            int       ProgressCounter = 0;
            DataTable Table           = null;
            string    selectedNids    = string.Empty;

            selectedNids = selectedGIds;

            // Initialize progress bar
            this.RaiseProgressBarInitialize(selectedGIds.Split(',').GetUpperBound(0) + 1);

            IndicatorBuilder             TrgIndicatorBuilderObj = null;
            IndicatorBuilder             SourceIndicatorBuilder = null;
            IndicatorInfo                IndicatorInfoObj       = null;
            Dictionary <string, DataRow> FileWithNids           = new Dictionary <string, DataRow>();

            DIConnection SourceDBConnection = null;
            DIQueries    SourceDBQueries    = null;

            //-- Step 1: Get TempTable with Sorted SourceFileName
            Table = this._TargetDBConnection.ExecuteDataTable(this.ImportQueries.GetImportIndicator(selectedNids));

            //-- Step 2:Initialise Indicator Builder with Target DBConnection
            TrgIndicatorBuilderObj = new IndicatorBuilder(this.TargetDBConnection, this.TargetDBQueries);

            //-- Step 3: Import Nids for each SourceFile
            foreach (DataRow Row in Table.Copy().Rows)
            {
                try
                {
                    string SourceFileWPath = Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SOURCEFILENAME]);

                    SourceDBConnection = new DIConnection(DIServerType.MsAccess, String.Empty, String.Empty, SourceFileWPath, String.Empty, MergetTemplateConstants.DBPassword);
                    SourceDBQueries    = DataExchange.GetDBQueries(SourceDBConnection);

                    // Get Source Indicator Info
                    SourceIndicatorBuilder = new IndicatorBuilder(SourceDBConnection, SourceDBQueries);
                    IndicatorInfoObj       = SourceIndicatorBuilder.GetIndicatorInfo(FilterFieldType.NId, Convert.ToString(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]), FieldSelection.Light);

                    // Import INdicator By Nid
                    TrgIndicatorBuilderObj.ImportIndicator(IndicatorInfoObj, Convert.ToInt32(Row[MergetTemplateConstants.Columns.COLUMN_SRCNID]), SourceDBQueries, SourceDBConnection);
                    ProgressCounter += 1;
                    this.RaiseProgressBarIncrement(ProgressCounter);
                }
                catch (Exception ex) { ExceptionFacade.ThrowException(ex); }
                finally
                {
                    if (SourceDBConnection != null)
                    {
                        SourceDBConnection.Dispose();
                    }
                    if (SourceDBQueries != null)
                    {
                        SourceDBQueries.Dispose();
                    }
                }
            }
            this._AvailableTable = this.GetAvailableTable();
            this._UnmatchedTable = this.GetUnmatchedTable();
            // Close ProgressBar
            this.RaiseProgressBarClose();
        }
Example #24
0
        /// <summary>
        /// Imports mapped values into database and returns unmatched elements info
        /// </summary>
        /// <param name="mappedValues"></param>
        /// <param name="dataValue"></param>
        /// <param name="denominator"></param>
        /// <returns></returns>
        public UnMatchedElementInfo ImportMappedValuesIntoDB(DIConnection dbConnection, DIQueries dbQueries, string dataValue, string denominator)
        {
            UnMatchedElementInfo RetVal = new UnMatchedElementInfo();

            int IndicatorNId = -1;
            int UnitNId      = -1;
            int SGNId        = -1;
            int IUSNId       = -1;

            int AreaNId       = -1;
            int SourceNId     = -1;
            int TimeperiodNId = -1;
            int DataNId       = -1;

            Dictionary <string, int> IUSNIds        = new Dictionary <string, int>();
            Dictionary <string, int> AreaNIds       = new Dictionary <string, int>();
            Dictionary <string, int> SourceNIds     = new Dictionary <string, int>();
            Dictionary <string, int> TimeperiodNIds = new Dictionary <string, int>();

            IndicatorBuilder      IndicatorBuilderObj;
            UnitBuilder           UnitBuilderObj;
            DI6SubgroupValBuilder SGValBuilderObj;
            IUSBuilder            IUSBuilderObj;

            AreaBuilder       AreaBuilderObj;
            SourceBuilder     SourceBuilderObj;
            TimeperiodBuilder TimeperiodBuilderObj;
            DIDatabase        TargetDatabase;

            try
            {
                IndicatorBuilderObj = new IndicatorBuilder(dbConnection, dbQueries);
                UnitBuilderObj      = new UnitBuilder(dbConnection, dbQueries);
                SGValBuilderObj     = new DI6SubgroupValBuilder(dbConnection, dbQueries);
                IUSBuilderObj       = new IUSBuilder(dbConnection, dbQueries);

                AreaBuilderObj       = new AreaBuilder(dbConnection, dbQueries);
                SourceBuilderObj     = new SourceBuilder(dbConnection, dbQueries);
                TimeperiodBuilderObj = new TimeperiodBuilder(dbConnection, dbQueries);
                TargetDatabase       = new DIDatabase(dbConnection, dbQueries);

                // import value
                if (this.IsVaildMappedValues())
                {
                    // check IUSNId in IUSNIDs list
                    if (IUSNIds.ContainsKey(this._IndicatorGID + this._UnitGID + this._SubgroupValGID))
                    {
                        IUSNId = IUSNIds[this._IndicatorGID + this._UnitGID + this._SubgroupValGID];
                    }

                    else
                    {
// indicator Nid
                        IndicatorNId = IndicatorBuilderObj.GetIndicatorNid(this._IndicatorGID, this._IndicatorName);

                        // UnitNId
                        UnitNId = UnitBuilderObj.GetUnitNid(this._UnitGID, this._UnitName);

                        // SG Val NID
                        SGNId = SGValBuilderObj.GetSubgroupValNid(this._SubgroupValGID, this._SubgroupVal);

                        //IUSNID
                        IUSNId = IUSBuilderObj.GetIUSNid(IndicatorNId, UnitNId, SGNId);

                        // if IUSNID <=0 then create the given IUS combinator into database
                        if (IUSNId <= 0)
                        {
                            IUSNId = IUSBuilderObj.InsertIUSIntoDB(this._IndicatorGID, this._UnitGID, this._SubgroupValGID);
                        }

                        IUSNIds.Add((this._IndicatorGID + this._UnitGID + this._SubgroupValGID), IUSNId);
                    }


                    if (IUSNId > 0)
                    {
                        // get AREANID
                        if (AreaNIds.ContainsKey(this._AreaID))
                        {
                            AreaNId = AreaNIds[this._AreaID];
                        }
                        else
                        {
                            AreaNId = AreaBuilderObj.GetAreaNidByAreaID(this._AreaID);
                            AreaNIds.Add(this._AreaID, AreaNId);
                        }

                        // get sourcenid
                        if (SourceNIds.ContainsKey(this._Source))
                        {
                            SourceNId = SourceNIds[this._Source];
                        }
                        else
                        {
                            SourceNId = SourceBuilderObj.CheckNCreateSource(this._Source);
                            SourceNIds.Add(this._Source, SourceNId);
                        }

                        // get timeperiodNId
                        if (TimeperiodNIds.ContainsKey(this._Timeperiod))
                        {
                            TimeperiodNId = TimeperiodNIds[this._Timeperiod];
                        }
                        else
                        {
                            TimeperiodNId = TimeperiodBuilderObj.CheckNCreateTimeperiod(this._Timeperiod);
                            TimeperiodNIds.Add(this._Timeperiod, TimeperiodNId);
                        }

                        if (AreaNId > 0 && IUSNId > 0 && SourceNId > 0 && TimeperiodNId > 0 && !string.IsNullOrEmpty(dataValue))
                        {
                            DataNId = TargetDatabase.CheckNCreateData(AreaNId, IUSNId, SourceNId, TimeperiodNId, dataValue);
                        }


                        // denominator value
                        if (!string.IsNullOrEmpty(denominator) && DataNId > 0)
                        {
                            try
                            {
                                TargetDatabase.UpdateDenominatorValue(DataNId, Convert.ToInt32(Convert.ToDecimal(denominator)));
                            }
                            catch (Exception ex)
                            {
                                throw new ApplicationException(ex.ToString());
                            }
                        }
                    }
                }

                // for log file
                if (!string.IsNullOrEmpty(dataValue))
                {
                    if (AreaNId <= 0 || IUSNId <= 0 || SourceNId <= 0 || TimeperiodNId <= 0)
                    {
                        // for log file
                        if (AreaNId <= 0)
                        {
                            RetVal.Areas.Add(this._AreaID, this._Area);
                        }
                        if (IndicatorNId <= 0)
                        {
                            RetVal.Indicators.Add(this._IndicatorGID, this._IndicatorName);
                        }
                        if (UnitNId <= 0)
                        {
                            RetVal.Units.Add(this._UnitGID, this._UnitName);
                        }
                        if (SGNId <= 0)
                        {
                            RetVal.Subgroups.Add(this._SubgroupValGID, this._SubgroupVal);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.ToString());
            }

            return(RetVal);
        }
        public async Task <Responses.Indicator> AddIndicator(AddIndicator request)
        {
            // Get user
            var user = await _mainDbContext.Users.FindAsync(request.UserId);

            // User not found
            if (user == null)
            {
                throw new NotFoundException(UserMessage.UserNotFound);
            }

            // Get indicator
            var indicator = await _mainDbContext.Indicators
                            .Include(x => x.Dependencies)
                            .FirstOrDefaultAsync(IndicatorExpression.Unique(request.UserId, request.Abbreviation));

            // Throw ConflictException if it exists
            if (indicator != null)
            {
                throw new ConflictException(new Conflict <AddIndicatorConflictReason>(AddIndicatorConflictReason.INDICATOR_ALREADY_EXISTS, IndicatorMessage.IndicatorWithSameIdAlreadyExists));
            }

            // Get dependencies
            var dependencies = await GetIndicators(request.Dependencies);

            // Build dependency level
            var dependencyLevel = IndicatorBuilder.BuildDependencyLevel(dependencies);

            // Build indicator dependencies
            var indicatorDependencies = IndicatorDependencyBuilder.BuildIndicatorDependencies(request.IndicatorId, dependencies);

            // Create
            indicator = new Indicator(
                request.UserId,
                request.Abbreviation,
                request.Name,
                request.Description,
                request.Formula,
                indicatorDependencies,
                dependencyLevel,
                DateTime.UtcNow.StripSeconds());

            // Add
            _mainDbContext.Indicators.Add(indicator);

            // Save
            await _mainDbContext.SaveChangesAsync();

            // Get indicator
            indicator = await _mainDbContext.Indicators
                        .Include(x => x.Dependencies)
                        .ThenInclude(x => x.Dependency)
                        .FirstOrDefaultAsync(x => x.IndicatorId == indicator.IndicatorId);

            // Response
            var response = _mapper.Map <Responses.Indicator>(indicator);

            // Log
            _logger.LogInformation("{@Event}, {@UserId}, {@Request}, {@Response}", "IndicatorAdded", request.UserId, request, response);

            // Return
            return(response);
        }