/// <summary> /// Build the code - description map for the specified component and add it to <see cref="_componentCodesDescriptionMap"/>. /// </summary> /// <param name="dim"> /// The component /// </param> private void BuildCodeDescriptionMap(IComponent dim) { Dictionary <string, string> codeDescriptionMap; if (!this._componentCodesDescriptionMap.TryGetValue(dim.Id, out codeDescriptionMap)) { codeDescriptionMap = new Dictionary <string, string>(StringComparer.Ordinal); this._componentCodesDescriptionMap.Add(dim.Id, codeDescriptionMap); } else { codeDescriptionMap.Clear(); } ICodelistObject codelist = this.GetCachedCodelist(dim); string lang = this.CurrentCulture.TwoLetterISOLanguageName; foreach (ICode code in codelist.Items) { string desc = TextTypeHelper.GetText(code.Names, lang); if (string.IsNullOrEmpty(desc)) { desc = code.Id; } codeDescriptionMap.Add(code.Id, desc); } }
public Dictionary <string, CodemapObj> ParseCodelist(Dictionary <string, ICodelistObject> Codemap) { Dictionary <string, CodemapObj> drcodemap = new Dictionary <string, CodemapObj>(); foreach (string conceptId in Codemap.Keys) { List <string> criteri = new List <string>(); ICodelistObject codelist = Codemap[conceptId]; CodemapObj codemap = new CodemapObj() { title = TextTypeHelper.GetText(codelist.Names, this.CodemapObj.Configuration.Locale), codes = new Dictionary <string, CodeObj>() }; foreach (ICode codeItem in codelist.Items.Where(ci => (criteri.Count > 0 ? criteri.Contains(ci.Id) : true))) { codemap.codes.Add( codeItem.Id.ToString(), new CodeObj() { name = TextTypeHelper.GetText(codeItem.Names, this.CodemapObj.Configuration.Locale), parent = codeItem.ParentCode }); } codemap.codes = codemap.codes.OrderBy(c => c.Value.parent == null).ToDictionary(c => c.Key, c => c.Value); drcodemap.Add(conceptId, codemap); } return(drcodemap); }
private void SetupNode(JsTreeNode node, INameableObject artefact, string defaultString, string format, string TwoLetterISOLanguageName) { string result = TextTypeHelper.GetText(artefact.Names, TwoLetterISOLanguageName); string title = string.Format(format, result.Length == 0 ? TextTypeHelper.GetText(artefact.Descriptions, TwoLetterISOLanguageName) : result); if (string.IsNullOrEmpty(title)) { title = defaultString; } node.text = title; }
public SessionImplObject GetData(out object DataStream, SessionQuery query) { try { // Init session objects if (this.SessionObj == null) { this.SessionObj = new SessionImplObject(); this.SessionObj.SdmxObject = new SdmxObjectsImpl(); } if (BDO == null || GetSDMXObject == null) { throw new Exception(Messages.label_error_network + " " + DataObj.Configuration.Title); } codemapWidget = new CodemapWidget(new GetCodemapObject() { Configuration = this.DataObj.Configuration, Dataflow = this.DataObj.Dataflow, PreviusCostraint = this.DataObj.Criteria }, this.SessionObj, query); //ISdmxObjects structure = codemapWidget.GetDsd(); ISdmxObjects structure = query.Structure; IDataflowObject df = structure.Dataflows.FirstOrDefault(); IDataStructureObject kf = structure.DataStructures.First(); if (df == null) { throw new InvalidOperationException("Dataflow is not set"); } /****************/ // Get all codelist /****************/ //Dictionary<string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(df, kf, true); Dictionary <string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(query, false); ComponentCodeDescriptionDictionary codemap = new ComponentCodeDescriptionDictionary(); foreach (string ConceptId in ConceptCodelists.Keys) { ICodelistObject codelist = ConceptCodelists[ConceptId]; Dictionary <string, string> codes = new Dictionary <string, string>(); foreach (ICode codeItem in codelist.Items) { codes.Add(codeItem.Id, TextTypeHelper.GetText(codeItem.Names, this.DataObj.Configuration.Locale)); } codemap.Add(ConceptId, codes); } /****************/ //codemapWidget.GetCodeListCostraint(df,kf,component) this.SessionObj.MergeObject(codemapWidget.SessionObj); int num1; #region Gestione last period if (this.DataObj.Criteria.ContainsKey(kf.TimeDimension.Id) && this.DataObj.Criteria[kf.TimeDimension.Id].Count == 1 && int.TryParse(this.DataObj.Criteria[kf.TimeDimension.Id].First(), out num1) && !this.DataObj.Layout.axis_z.Contains(kf.TimeDimension.Id)) { int offsetTime = int.Parse(this.DataObj.Criteria[kf.TimeDimension.Id].First()); var codMap = codemap; int lengthTime = codMap[kf.TimeDimension.Id].Count; if ((lengthTime - offsetTime) >= 0) { var codes = codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime); List <string> _criteriaTime = (from c in codes select c.Key).ToList <string>(); this.DataObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last()); this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First()); } else { this.DataObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key); this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key); } } #endregion LayoutObj layObj = InitLayout(df, kf); List <DataCriteria> Criterias = BDO.InitCriteria(kf, this.DataObj.Criteria); //query.GetCriteria(); Dictionary <string, List <DataChacheObject> > DataCache = SessionObj.DataCache; List <string> ret = null; List <DataCriteria> QueryCriterias = new List <DataCriteria>(); if (query.Criteria != null) //criteri nulli se proviene da un template { if (query._store != null) //.Count == 1) { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); } if (query.Criteria.TryGetValue(kf.TimeDimension.Id, out ret)) { if (ret.Count == 1) { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); } } QueryCriterias = query.GetCriteria(); /*if (query._store == null) //.Count == 1) * { QueryCriterias = Criterias; } * else * { QueryCriterias = query.GetCriteria(); }*/ } else { QueryCriterias = Criterias; } //aggiunta da fabio IDataSetStore store; if (query._store != null) { store = query._store; } else { //store = BDO.GetDataset(df, kf, Criterias, ref DataCache, _useAttr); store = BDO.GetDataset(df, kf, QueryCriterias, ref DataCache, _useAttr, query); query._store = store; } //fine nuovo SessionObj.DataCache = DataCache; DataStream = new DataObjectForStreaming() { Configuration = this.DataObj.Configuration, store = store, layObj = layObj, Criterias = Criterias, structure = structure, codemap = codemap }; return(this.SessionObj); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw ex; } }
public SessionImplObject GetDataChart(SessionQuery sessionQuery) { try { // Init session objects if (this.SessionObj == null) { this.SessionObj = new SessionImplObject(); this.SessionObj.SdmxObject = new SdmxObjectsImpl(); } JavaScriptSerializer ser = new JavaScriptSerializer(); ser.MaxJsonLength = int.MaxValue; #region +++ Caching +++ ConnectionStringSettings connectionStringSetting; CacheWidget cache = null; bool UseWidgetCache = (WebClientSettings.Instance != null) ? WebClientSettings.Instance.UseWidgetCache : false; if (UseWidgetCache) { connectionStringSetting = ConfigurationManager.ConnectionStrings["ISTATWebClientConnection"]; cache = new CacheWidget(connectionStringSetting.ConnectionString); } if (ChartObj.WidgetId > 0 && UseWidgetCache) { SavedWidget widget = cache.GetWidget(ChartObj.WidgetId, ChartObj.Configuration.Locale); if (widget != null && !String.IsNullOrEmpty(widget.widgetData)) { this.SessionObj.SavedChart = widget.widgetData; return(this.SessionObj); } } #endregion if (BDO == null || GetSDMXObject == null) { throw new Exception(Messages.label_error_network); } codemapWidget = new CodemapWidget( new GetCodemapObject() { PreviusCostraint = this.ChartObj.Criteria, Configuration = this.ChartObj.Configuration, Dataflow = this.ChartObj.Dataflow }, this.SessionObj, sessionQuery); //ISdmxObjects structure = codemapWidget.GetDsd(); //IDataflowObject df = structure.Dataflows.FirstOrDefault(); //IDataStructureObject kf = structure.DataStructures.First(); ISdmxObjects structure = sessionQuery.Structure; //IDataflowObject df = structure.Dataflows.First(); IDataflowObject df = sessionQuery.Dataflow; //IDataStructureObject kf = structure.DataStructures.First(); IDataStructureObject kf = sessionQuery.KeyFamily; if (kf == null) { throw new InvalidOperationException("DSD is not set"); } if (df == null) { throw new InvalidOperationException("Dataflow is not set"); } Dictionary <string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(df, kf, false); ComponentCodeDescriptionDictionary codemap = new ComponentCodeDescriptionDictionary(); foreach (string ConceptId in ConceptCodelists.Keys) { ICodelistObject codelist = ConceptCodelists[ConceptId]; Dictionary <string, string> codes = new Dictionary <string, string>(); foreach (ICode codeItem in codelist.Items) { codes.Add(codeItem.Id, TextTypeHelper.GetText(codeItem.Names, this.ChartObj.Configuration.Locale)); } codemap.Add(ConceptId, codes); //var useFix20 = (ConfigurationManager.AppSettings["UseFix20Criteria"].ToString().ToLower() == "true"); //fabio prova var useFix20 = (ConfigurationManager.AppSettings["UseFix20Criteria"].ToString().ToLower() == "false"); if (useFix20) { if (!(codelist.Items.Count > 1)) { this.ChartObj.Criteria.Remove(ConceptId); } } } this.SessionObj.MergeObject(codemapWidget.SessionObj); #region Gestione last period int num1; if (this.ChartObj.Criteria.ContainsKey(kf.TimeDimension.Id) && this.ChartObj.Criteria[kf.TimeDimension.Id].Count == 1 && int.TryParse(this.ChartObj.Criteria[kf.TimeDimension.Id].First(), out num1) ) { int offsetTime = int.Parse(this.ChartObj.Criteria[kf.TimeDimension.Id].First()); var codMap = codemap; int lengthTime = codMap[kf.TimeDimension.Id].Count; if ((lengthTime - offsetTime) >= 0) { var codes = codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime); List <string> _criteriaTime = (from c in codes select c.Key).ToList <string>(); this.ChartObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last()); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First()); } else { this.ChartObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key); this.ChartObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key); } } #endregion List <DataCriteria> Criterias = BDO.InitCriteria(kf, this.ChartObj.Criteria); //List<DataCriteria> Criterias = sessionQuery.GetCriteria(); Dictionary <string, List <DataChacheObject> > DataCache = SessionObj.DataCache; //aggiunta da fabio //IDataSetStore store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false, sessionQuery); IDataSetStore store = sessionQuery._store; store.SetCriteria(Criterias); /* * IDataSetStore store; * if (sessionQuery._store != null) * { store = sessionQuery._store; } * else * { * //store = BDO.GetDataset(df, kf, Criterias, ref DataCache, _useAttr); * store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false, sessionQuery); * sessionQuery._store = store; * } */ //fine nuovo //string DBFileName = null; //IDataSetStore store = BDO.FindDataCache(df, kf, Criterias, ref DataCache, false, out DBFileName); //if (store == null) store = BDO.GetDataset(df, kf, Criterias, ref DataCache); //if (store == null) store = BDO.GetDataset(df, kf, Criterias, ref DataCache, false); //da vedere se eliminare aggiunta fabio per svuotare datacache SessionObj.DataCache = null; SessionObj.DataCache = DataCache; DataObjectForStreaming DataStream = new DataObjectForStreaming() { store = store, Criterias = Criterias, structure = structure, codemap = codemap }; ChartResponseObject ChartResponse = new ChartResponseObject(); ChartResponse.series_title = TextTypeHelper.GetText(df.Names, this.ChartObj.Configuration.Locale); ChartResponse.series = BuildChart(store, kf, ConceptCodelists); ChartResponse.primary_name = (this.ChartObj.ObsValue[0] == "v") ? Messages.label_varValue : (this.ChartObj.ObsValue[0] == "vt") ? Messages.label_varTrend : (this.ChartObj.ObsValue[0] == "vc") ? Messages.label_varCyclical : string.Empty; ChartResponse.secondary_name = (this.ChartObj.ObsValue.Count > 1) ? (this.ChartObj.ObsValue[1] == "v") ? Messages.label_varValue : (this.ChartObj.ObsValue[1] == "vt") ? Messages.label_varTrend : (this.ChartObj.ObsValue[1] == "vc") ? Messages.label_varCyclical : string.Empty : string.Empty; ChartResponse.x_name = (!string.IsNullOrEmpty(ChartObj.DimensionAxe)) ? ChartObj.DimensionAxe : kf.TimeDimension.Id;; // 23/07/2015 // calcolo massimo e minimo decimal?primary_max = null; decimal?primary_min = null; decimal?secondary_max = null; decimal?secondary_min = null; decimal costantemax = 1.1m; decimal costantemin = 0.9m; foreach (serieType serie in ChartResponse.series) { if (serie.axisYType == "secondary") { //fabio 12/08/2015 //decimal max = (decimal)serie.dataPoints.Where(m => m.y != null).Max(d => d.y); decimal max = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Max(d => d.y)); if (secondary_max == null || max > secondary_max) { secondary_max = max; } //fabio 12/08/2015 //decimal min = (decimal)serie.dataPoints.Where(m => m.y != null).Min(d => d.y); decimal min = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Min(d => d.y)); if (secondary_min == null || min < secondary_min) { secondary_min = min; } //fabio 12/08/2015 if (secondary_min == secondary_max) { secondary_min = secondary_min * costantemin; secondary_max = secondary_max * costantemax; } } else { //fabio 12/08/2015 //decimal max = (decimal)serie.dataPoints.Where(m => m.y != null).Max(d => d.y); decimal max = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Max(d => d.y)); if (primary_max == null || max > primary_max) { primary_max = max; } //fabio 12/08/2015 //decimal min = (decimal)serie.dataPoints.Where(m => m.y != null).Min(d => d.y); decimal min = Convert.ToDecimal(serie.dataPoints.Where(m => m.y != null).Min(d => d.y)); if (primary_min == null || min < primary_min) { primary_min = min; } //fabio 12/08/2015 if (primary_min == primary_max) { primary_min = primary_min * costantemin; primary_max = primary_max * costantemax; } } } if (primary_max != null && primary_min != null) { //decimal delta = (decimal)primary_max - (decimal)primary_min; //ChartResponse.primary_max = (decimal)primary_max; //ChartResponse.primary_min = (decimal)primary_min; if (primary_max > 0) { ChartResponse.primary_max = (decimal)(primary_max * 1.1m); } else if (primary_max == 0) { ChartResponse.primary_max = (decimal) - 1.1m; } else { ChartResponse.primary_max = (decimal)(primary_max * 0.9m); } if (primary_min > 0) { ChartResponse.primary_min = (decimal)(primary_min * 0.9m); } else if (primary_min == 0) { ChartResponse.primary_min = (decimal) - 1.1m; } else { ChartResponse.primary_min = (decimal)(primary_min * 1.1m); } } if (secondary_max != null && secondary_min != null) { //ChartResponse.secondary_max = (decimal)secondary_max; //ChartResponse.secondary_min = (decimal)secondary_min; if (secondary_max > 0) { ChartResponse.secondary_max = (decimal)(secondary_max * 1.1m); } else if (secondary_max == 0) { ChartResponse.secondary_max = (decimal) - 1.1m; } else { ChartResponse.secondary_max = (decimal)(secondary_max * 0.9m); } if (secondary_min > 0) { ChartResponse.secondary_min = (decimal)(secondary_min * 0.9m); } else if (secondary_min == 0) { ChartResponse.secondary_min = (decimal) - 1.1m; } else { ChartResponse.secondary_min = (decimal)(secondary_min * 1.1m); } } this.SessionObj.SavedChart = ser.Serialize(ChartResponse); // +++ Caching +++ if (ChartObj.WidgetId > 0 && UseWidgetCache) { cache.InsertWidget(ChartObj.WidgetId, this.SessionObj.SavedChart, ChartObj.Configuration.Locale); } return(this.SessionObj); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw ex; } }
private List <serieType> BuildChart( IDataSetStore store, IDataStructureObject kf, Dictionary <string, ICodelistObject> codelists) { List <string> sort = new List <string>(); foreach (string col in store.GetAllColumns()) { if (col != kf.TimeDimension.Id && col != kf.PrimaryMeasure.Id) { sort.Add(col); } } store.SetSort(sort); // Dimensione sull'asse X string XConcept = (!string.IsNullOrEmpty(ChartObj.DimensionAxe)) ? ChartObj.DimensionAxe : kf.TimeDimension.Id; // Codici sull'asse X Dictionary <string, int> XPosition = new Dictionary <string, int>(); if (codelists.ContainsKey(XConcept)) { ICodelistObject CCodes = codelists[XConcept]; for (int i = 0; i < CCodes.Items.Count; i++) { XPosition.Add(CCodes.Items[i].Id, i); } } #region Dimensione usata per la descrizione string DescConcept = string.Empty; bool single_serie = true; foreach (var obj in ChartObj.Criteria) { if (//obj.Key != kf.TimeDimension.Id && obj.Key != kf.FrequencyDimension.Id) { DescConcept = obj.Key; if (obj.Value.Count > 1 && obj.Key != XConcept) { single_serie = false; DescConcept = obj.Key; break; } } } bool inLegend = !single_serie; inLegend = inLegend || (single_serie && ChartObj.ObsValue.Count > 1); #endregion List <serieType> series = new List <serieType>(); List <serieType> series_s = new List <serieType>(); var v = new Dictionary <string, decimal>(); //IDataReader datareader = store.CreateDataReader(true); IDataReader datareader = store.CreateDataReader(false); while (datareader.Read()) { decimal obs = 0; object vt = null; object vc = null; var obs_val = datareader[kf.PrimaryMeasure.Id]; var xcode = (string)datareader[XConcept]; var xCodeName = (string)TextTypeHelper.GetText(codelists[XConcept].GetCodeById(xcode).Names, this.ChartObj.Configuration.Locale); //fabio 12/08/2015 //string customKeyCode = (ChartObj.CustomKey != null) ? datareader[ChartObj.CustomKey].ToString() : string.Empty; string customKeyCode = (ChartObj.CustomKey != null && ChartObj.CustomKey != "") ? datareader[ChartObj.CustomKey].ToString() : string.Empty; var customSerie = (ChartObj.CustomChartType != null) ? (!string.IsNullOrEmpty(customKeyCode)) ? (from c in ChartObj.CustomChartType where c.code == customKeyCode select c).FirstOrDefault() : null : null; string serieKey = string.Empty; string serieName = string.Empty; bool is_obs_value = false; try { obs = Convert.ToDecimal(obs_val.ToString(), cFrom); is_obs_value = true; obs_val = Math.Round(obs, 1); } catch { //fabio 12/08/2015 aggiunta obs_val = null; is_obs_value = true; //fabio 12/08/2015 eliminata //is_obs_value = false; } // if not time serie no varation if (XConcept == kf.TimeDimension.Id) { #region Calcolo variazioni if (is_obs_value) { var time_p = xcode; int anno = 0; int period = 0; bool _errTimePeriod = false; bool _annual = !((string)time_p).Contains("-"); bool _quater = false; bool _seme = false; #region ESTRAGGO ANNO E PERIOD if (_annual) { _errTimePeriod = !(int.TryParse(((string)time_p), out anno)); } else { _errTimePeriod = !(int.TryParse(((string)time_p).Split('-')[0], out anno)); string _p = ((string)time_p).Split('-')[1]; if (_quater = _p.StartsWith("Q")) { _p = _p.Substring(1); } if (_seme = _p.StartsWith("S")) { _p = _p.Substring(1); } _errTimePeriod = !(int.TryParse(_p, out period)); } #endregion if (!_errTimePeriod) { string serieKeyStr = string.Empty; string _sep = string.Empty; foreach (var dim in kf.DimensionList.Dimensions) { serieKeyStr += ((dim.Id != XConcept) ? _sep + datareader[dim.Id] : string.Empty); _sep = "+"; if (dim.Id == DescConcept) { serieName = TextTypeHelper.GetText( codelists[DescConcept].GetCodeById(datareader[dim.Id].ToString()).Names, this.ChartObj.Configuration.Locale); } } serieKey = serieKeyStr; string vi_k = string.Empty; string vf_k = string.Empty; // Calcolo variazione congiunturale vf_k = serieKeyStr + anno + "_" + (period); if (!_annual) { if (period == 1) { if (_seme) { vi_k = serieKeyStr + (anno - 1) + "_2"; } else if (_quater) { vi_k = serieKeyStr + (anno - 1) + "_4"; } else { vi_k = serieKeyStr + (anno - 1) + "_12"; } } else { vi_k = serieKeyStr + anno + "_" + (period - 1); } } else { vi_k = serieKeyStr + (anno - 1) + "_" + (period); } var vi = (v.ContainsKey(vi_k.ToString())) ? (object)v[vi_k] : null; try { decimal _vi; // non specificare il cFrom nella conversione // poichè vi è il valore gia convertito _vi = Convert.ToDecimal(vi.ToString()); //_vi = Convert.ToDecimal(vi.ToString(), cFrom); if (_vi == 0) { vc = null; } else { vc = Math.Round((((obs - _vi) / _vi) * 100), 1); } } catch { vc = null; } // Calcolo variazione tendenziale vi_k = serieKeyStr + (anno - 1) + "_" + (period); vf_k = serieKeyStr + anno + "_" + (period); vi = (v.ContainsKey(vi_k.ToString())) ? (object)v[vi_k] : null; try { decimal _vi; _vi = Convert.ToDecimal(vi.ToString()); //_vi = Convert.ToDecimal(vi.ToString(), cFrom); if (_vi == 0) { vc = null; } else { vt = Math.Round((((obs - _vi) / _vi) * 100), 1); } } catch { vt = null; } v.Add(vf_k, obs); } } #endregion } else { // Retrive unique key and label serie string serieKeyStr = string.Empty; string _sep = string.Empty; foreach (var dim in kf.DimensionList.Dimensions) { serieKeyStr += ((dim.Id != XConcept) ? _sep + datareader[dim.Id] : string.Empty); _sep = "+"; if (dim.Id == DescConcept) { serieName = TextTypeHelper.GetText( codelists[DescConcept].GetCodeById(datareader[dim.Id].ToString()).Names, this.ChartObj.Configuration.Locale); } } serieKey = serieKeyStr; } #region Primary Serie object primary_obs = (ChartObj.ObsValue[0] == "v") ? (is_obs_value) ? obs_val : null : (ChartObj.ObsValue[0] == "vt") ? vt : (ChartObj.ObsValue[0] == "vc") ? vc : null; bool isNew = false; serieType newSerie = null; newSerie = series.Find(s => s.serieKey == ChartObj.ObsValue[0] + "_" + serieKey);//SerieName); if (newSerie == null) { string _type = (customSerie != null) ? customSerie.chartType.ToString() : ChartObj.ChartType; string _name = (ChartObj.ObsValue[0] == "vt") ? Messages.label_varTrend + "% " : (ChartObj.ObsValue[0] == "vc") ? Messages.label_varCyclical + "% " : (single_serie)? Messages.label_varValue: string.Empty; if (!single_serie) { _name += ((customSerie != null) ? customSerie.title.ToString() : serieName); } isNew = true; newSerie = new serieType() { name = _name, serieKey = ChartObj.ObsValue[0] + "_" + serieKey, showInLegend = inLegend, type = _type, dataPoints = new List <dataPointType>(), axisYType = "primary", lineThickness = 1f, markerType = "circle", //"circle", "square", "cross", "none" markerSize = (_type == "bubble" || _type == "scatter") ? 10f : 1f, }; } newSerie.dataPoints.Add(new dataPointType() { label = xCodeName, legendText = xCodeName, y = primary_obs, x = XPosition[xcode] }); if (isNew) { series.Add(newSerie); } #endregion // if not time serie no secondary if (XConcept == kf.TimeDimension.Id) { #region Seconday serie if (ChartObj.ObsValue.Count > 1) { string _type = (customSerie != null) ? customSerie.chartType.ToString() : ChartObj.ChartType; string _name = (ChartObj.ObsValue[1] == "vt") ? Messages.label_varTrend + "% " : (ChartObj.ObsValue[1] == "vc") ? Messages.label_varCyclical + "% " : Messages.label_varValue + " "; if (!single_serie) { _name += ((customSerie != null) ? customSerie.title.ToString() : serieName); } object secondary_obs = (ChartObj.ObsValue[1] == "v") ? (is_obs_value) ? obs_val : null : (ChartObj.ObsValue[1] == "vt") ? vt : (ChartObj.ObsValue[1] == "vc") ? vc : null; bool isNew_s = false; serieType newSerie_s = null; newSerie_s = series_s.Find(s => s.serieKey == ChartObj.ObsValue[1] + "_" + serieKey);//SerieName); if (newSerie_s == null) { isNew_s = true; newSerie_s = new serieType() { name = _name, serieKey = ChartObj.ObsValue[1] + "_" + serieKey, showInLegend = inLegend, type = _type, dataPoints = new List <dataPointType>(), axisYType = "secondary", lineThickness = 1f, markerType = "circle", //"circle", "square", "cross", "none" markerSize = (_type == "bubble" || _type == "scatter") ? 10f : 1f, }; } newSerie_s.dataPoints.Add(new dataPointType() { label = xCodeName, legendText = xCodeName, y = secondary_obs, x = XPosition[xcode] }); if (isNew_s) { series_s.Add(newSerie_s); } } #endregion } } series.AddRange(series_s); #region Series foreach (var serie in series) { var sortedCodes = serie.dataPoints.OrderBy <dataPointType, int>(o => int.Parse(o.x.ToString())).ToArray(); serie.dataPoints.Clear(); serie.dataPoints.AddRange(sortedCodes); for (int i = 0; i < serie.dataPoints.Count; i++) { serie.dataPoints[i].x = i; } } #endregion return(series); }
/// <summary> /// Create a Dataflow Node /// </summary> /// <param name="dataflow"> /// The SDMX Model Dataflow object /// </param> /// <returns> /// The Dataflow Node /// </returns> private JsTreeNode CreateDataflowNode( IDataflowObject dataflow, ISdmxObjects SdmxOBJ, string TwoLetterISO) { var dataflowNode = new JsTreeNode(); if (dataflow.HasAnnotationType(VirtualDataflowTypeEpAnn)) { // VIrtual DF var vrtDf = dataflow.GetAnnotationsByType(VirtualDataflowTypeEpAnn); var value = TextTypeHelper.GetText(vrtDf.FirstOrDefault().Text, TwoLetterISO); string end_key = "@"; string search_key = string.Empty; search_key = "@EP1="; string endpoint_1 = value.Substring(value.IndexOf(search_key) + search_key.Length); endpoint_1 = endpoint_1.Substring(0, endpoint_1.IndexOf(end_key)); search_key = "@EP2="; string endpoint_2 = value.Substring(value.IndexOf(search_key) + search_key.Length); endpoint_2 = endpoint_2.Substring(0, endpoint_2.IndexOf(end_key)); search_key = "@EPT="; string endpoint_type = value.Substring(value.IndexOf(search_key) + search_key.Length); endpoint_type = endpoint_type.Substring(0, endpoint_type.IndexOf(end_key)); search_key = "@SOURCE="; string dataflow_source = value.Substring(value.IndexOf(search_key) + search_key.Length); dataflow_source = dataflow_source.Substring(0, dataflow_source.IndexOf(end_key)); search_key = "@SEP="; string decimal_separator = ""; if (value.IndexOf(search_key) != -1) { decimal_separator = value.Substring(value.IndexOf(search_key) + search_key.Length); decimal_separator = decimal_separator.Substring(0, decimal_separator.IndexOf(end_key)); } else { decimal_separator = TreeObj.Configuration.DecimalSeparator; } //fabio forzo il sep prova debug del separatore decimale //if (dataflow.Id == "PARAS") { decimal_separator = ","; } List <string> valueDesc = new List <string>(); if (dataflow.HasAnnotationType(VirtualDataflowTypeDescAnn)) { var vrtDfDesc = dataflow.GetAnnotationsByType(VirtualDataflowTypeDescAnn); foreach (var ann in vrtDfDesc) { valueDesc.Add(TextTypeHelper.GetText(ann.Text, TwoLetterISO)); } } List <DataflowMetaUrl> valueUrls = new List <DataflowMetaUrl>(); if (dataflow.HasAnnotationType(VirtualDataflowTypeUrlAnn)) { var vrtDfUrls = dataflow.GetAnnotationsByType(VirtualDataflowTypeUrlAnn); foreach (var ann in vrtDfUrls) { valueUrls.Add(new DataflowMetaUrl() { Title = TextTypeHelper.GetText(ann.Text, TwoLetterISO), URL = ann.Title }); } } dataflowNode = CreateDataflowNode( dataflow.Id, dataflow.Version, dataflow.AgencyId, TextTypeHelper.GetText(dataflow.Names, TwoLetterISO), endpoint_1, endpoint_2, endpoint_type, dataflow_source, decimal_separator, valueDesc, valueUrls); } else { // Normal DF dataflowNode.SetId(Utils.MakeKey(dataflow).Replace('.', '_').Replace('+', '-')); SetupNode(dataflowNode, dataflow, TwoLetterISO); IDataStructureObject dsd = SdmxOBJ.DataStructures.FirstOrDefault( dataStructure => dataflow.DataStructureRef.Equals(dataStructure.AsReference)); if (dsd != null && dsd is ICrossSectionalDataStructureObject) { dataflowNode.SetRel("xs-dataflow"); dataflowNode.type = "xs-dataflow"; } else { dataflowNode.SetRel("dataflow"); dataflowNode.type = "dataflow"; } dataflowNode.li_attr.Add("title", TreeObj.Configuration.Title); dataflowNode.a_attr = new JSTreeMetadata { DataflowID = dataflow.Id, DataflowVersion = dataflow.Version, DataflowAgency = dataflow.AgencyId, DataflowUrl = TreeObj.Configuration.EndPoint, DataflowUrlV20 = TreeObj.Configuration.EndPointV20, DataflowUrlType = TreeObj.Configuration.EndPointType, DataflowSource = TreeObj.Configuration.EndPointSource, DataflowDecimalCulture = TreeObj.Configuration.DecimalSeparator, }; } return(dataflowNode); }
public SessionImplObject Get_DOTSTAT_CodemapAndLayout(ConnectionStringSettings connectionStringSetting) { try { ISdmxObjects structure = GetDsd(); //IDataflowObject df = structure.Dataflows.First(); IDataStructureObject kf = structure.DataStructures.First(); if (kf == null) { throw new InvalidOperationException("DataStructure is not set"); } Dictionary <string, ICodelistObject> ConceptCodelists = GetCodeMap(structure, kf, false); string costraint = string.Empty; //the code save in template string hideDimension = string.Empty; System.Data.SqlClient.SqlConnection Sqlconn = new System.Data.SqlClient.SqlConnection(connectionStringSetting.ConnectionString); Sqlconn.Open(); string sqlquery = string.Format("Select * from Template where [tmplKey]='{0}'", new System.Web.Script.Serialization.JavaScriptSerializer().Serialize( CodemapObj.Dataflow.id + "+" + CodemapObj.Dataflow.agency + "+" + CodemapObj.Dataflow.version + "+" + CodemapObj.Configuration.EndPoint).Replace("'", "''")); using (System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand(sqlquery, Sqlconn)) { var reader = comm.ExecuteReader(); if (reader.Read()) { costraint = reader.GetString(reader.GetOrdinal("Criteria")); hideDimension = reader.GetString(reader.GetOrdinal("HideDimension")); } } Sqlconn.Close(); Dictionary <string, List <string> > _costraint = (Dictionary <string, List <string> >) new JavaScriptSerializer().Deserialize(costraint, typeof(Dictionary <string, List <string> >)); List <string> _hideDimension = (List <string>) new JavaScriptSerializer().Deserialize(hideDimension, typeof(List <string>)); CodemapResponseObject codemapret = new CodemapResponseObject() { codemap = ParseCodelist(ConceptCodelists), costraint = _costraint, hideDimension = _hideDimension, key_time_dimension = kf.TimeDimension.Id, freq_dimension = null, dataflow = new MaintenableObj() { id = kf.Id, agency = kf.AgencyId, version = kf.Version, name = TextTypeHelper.GetText(kf.Names, this.CodemapObj.Configuration.Locale), description = TextTypeHelper.GetText(kf.Descriptions, this.CodemapObj.Configuration.Locale) } }; this.SessionObj.SavedCodemap = new JavaScriptSerializer().Serialize(codemapret); return(this.SessionObj); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw new Exception(ErrorOccured); } }