public void GenerateNewNonDraggableSegmentObject() { List <KeyValuePair <int, int> > availableSegments = GetAvailableSegments(); // Если свободных ячеек нет, то не создает if (availableSegments.Count == 0) { SegmentsRemainingAvailable = false; return; } int index = UnityEngine.Random.Range(0, availableSegments.Count); var freeSegment = gridSegments[availableSegments[index].Key, availableSegments[index].Value]; SegmentObject newNotDraggableObject = Instantiate(notDraggableObjectPrefabs[UnityEngine.Random.Range(0, notDraggableObjectPrefabs.Length)], segmentObjectsContainer); newNotDraggableObject.transform.position = freeSegment.transform.position; newNotDraggableObject.transform.localScale = Vector3.zero; newNotDraggableObject.transform.DOScale(Vector3.one, 0.2f); newNotDraggableObject.Id = currentSegmentId; currentSegmentId++; freeSegment.IsFree = false; freeSegment.OccupiedObject = newNotDraggableObject; availableSegments.Clear(); CheckLinesForFullness(); }
/// <summary> /// Генерирует начальные сегменты-объекты на сетке /// </summary> /// <returns></returns> private IEnumerator GenerateInitialSegments() { yield return(new WaitForSeconds(0.1f)); SegmentObject newPlayerObject = Instantiate(playerPrefab, segmentObjectsContainer); newPlayerObject.transform.position = gridSegments[2, 2].transform.position; newPlayerObject.gameObject.GetComponentInChildren <Renderer>().material.color = GameManager.Source.ColorManager.ColorSet.PlayerColor; newPlayerObject.gameObject.GetComponentInChildren <TrailRenderer>().startColor = GameManager.Source.ColorManager.ColorSet.PlayerColor; newPlayerObject.gameObject.GetComponentInChildren <TrailRenderer>().endColor = GameManager.Source.ColorManager.ColorSet.PlayerColor; newPlayerObject.transform.localScale = Vector3.zero; newPlayerObject.transform.DOScale(new Vector3(1f, 1f, 2f), 0.2f); gridSegments[2, 2].IsFree = false; gridSegments[2, 2].OccupiedObject = newPlayerObject; // Подписывается на события, срабатывающие после каждого передвижения игрока newPlayerObject.GetComponent <PlayerMovementHandler>().OnPlayerMadeMove += GridManager_OnPlayerMadeMove; yield return(new WaitForSeconds(0.5f)); int initialNumberOfSegments = 9; List <KeyValuePair <int, int> > availableSegments = GetAvailableSegments(true); for (int i = 0; i < initialNumberOfSegments; i++) { yield return(new WaitForSeconds(0.05f)); int index = Random.Range(0, availableSegments.Count); var freeSegment = gridSegments[availableSegments[index].Key, availableSegments[index].Value]; SegmentObject newPushedObject = Instantiate(draggableObjectPrefabs[Random.Range(0, draggableObjectPrefabs.Length)], segmentObjectsContainer); newPushedObject.transform.position = freeSegment.transform.position; newPushedObject.transform.localScale = Vector3.zero; newPushedObject.transform.DOScale(Vector3.one, 0.2f); newPushedObject.gameObject.GetComponentInChildren <Renderer>().material.color = GameManager.Source.ColorManager.ColorSet.MovableObjectColor; freeSegment.IsFree = false; freeSegment.OccupiedObject = newPushedObject; freeSegment.OccupiedObject.Id = currentSegmentId; currentSegmentId++; availableSegments.RemoveAt(index); } DoPlayerInitialCompleted(); DoInitialSegmentGenerationCompleted(); }
public static SegmentObject Map(SegmentRequest request) { var traceSegment = new SegmentObject { TraceId = request.TraceId, //todo: is there chances request.UniqueIds.Count > 1 ? TraceSegmentId = request.Segment.SegmentId, Service = request.Segment.ServiceId, ServiceInstance = request.Segment.ServiceInstanceId, IsSizeLimited = false }; traceSegment.Spans.Add(request.Segment.Spans.Select(MapToSpan).ToArray()); return(traceSegment); }
/// <summary> /// Returns a segment value that matches patterns in the auto segment configuration, or null if nothing is found. /// </summary> /// <param name="segment">The segment type to extract (uses this segment's configuration).</param> /// <param name="source">The string to search.</param> /// <param name="defaultFragmentValues">If not found using the regex pattern, use these values.</param> /// <returns></returns> public SegmentObject ExtractSegmentValue(Segment segment, string source, string patternName = null, Dictionary <string, string> defaultFragmentValues = null) { if (this.Definitions == null) { return(null); } if (segment == null) { throw new ArgumentNullException("segment"); } if (source == null) { throw new ArgumentNullException("source", "Segments can only be extracted from a non-null source."); } AutoSegmentDefinition def = this.Definitions[segment.Name]; if (def == null) { throw new ArgumentException(String.Format("The segment '{0}' was not found in the {1} configuration.", segment.Name, AutoSegmentDefinitionCollection.ExtensionName), "segmentName"); } var fragmentValues = new Dictionary <string, string>(); SegmentObject value = null; if (patternName == null) { // Find a definition that works for (int p = 0; p < def.Patterns.Count && value == null; p++) { // reset because previous iteration found nothing fragmentValues.Clear(); value = ExtractSegmentValueFromPattern(segment, source, defaultFragmentValues, fragmentValues, def.Patterns[p]); } } else { value = ExtractSegmentValueFromPattern(segment, source, defaultFragmentValues, fragmentValues, def.Patterns[patternName]); } return(value); }
public static UpstreamSegment Map(SegmentRequest request) { var upstreamSegment = new UpstreamSegment(); upstreamSegment.GlobalTraceIds.AddRange(request.UniqueIds.Select(MapToUniqueId).ToArray()); var traceSegment = new SegmentObject { TraceSegmentId = MapToUniqueId(request.Segment.SegmentId), ServiceId = request.Segment.ServiceId, ServiceInstanceId = request.Segment.ServiceInstanceId, IsSizeLimited = false }; traceSegment.Spans.Add(request.Segment.Spans.Select(MapToSpan).ToArray()); upstreamSegment.Segment = traceSegment.ToByteString(); return(upstreamSegment); }
/// <summary> /// Генерирует новый перетаскиваемый объект-сегмент на сетке /// </summary> public void GenerateNewDraggableSegmentObject() { List <KeyValuePair <int, int> > availableSegments = GetAvailableSegments(); // Если свободных ячеек нет, то не создает if (availableSegments.Count == 0) { SegmentsRemainingAvailable = false; return; } int index = UnityEngine.Random.Range(0, availableSegments.Count); var freeSegment = gridSegments[availableSegments[index].Key, availableSegments[index].Value]; // Если содержит бонус, то уничтожает его if (freeSegment.ContainsBonus) { freeSegment.DestroyBonus(); } SegmentObject newDraggableObject = Instantiate(draggableObjectPrefabs[UnityEngine.Random.Range(0, draggableObjectPrefabs.Length)], segmentObjectsContainer); newDraggableObject.transform.position = freeSegment.transform.position; newDraggableObject.Id = currentSegmentId; newDraggableObject.transform.localScale = Vector3.zero; newDraggableObject.transform.DOScale(Vector3.one, 0.2f); newDraggableObject.gameObject.GetComponentInChildren <Renderer>().material.color = GameManager.Source.ColorManager.ColorSet.MovableObjectColor; currentSegmentId++; freeSegment.IsFree = false; freeSegment.OccupiedObject = newDraggableObject; availableSegments.Clear(); CheckLinesForFullness(); }
protected override Core.Services.ServiceOutcome DoPipelineWork() { MappingContainer metricsUnitMapping; if (!this.Mappings.Objects.TryGetValue(typeof(GenericMetricsUnit), out metricsUnitMapping)) { throw new MappingConfigurationException("Missing mapping definition for GenericMetricsUnit."); } currentOutput = this.Delivery.Outputs.First(); currentOutput.Checksum = new Dictionary <string, double>(); Dictionary <string, int> columns = new Dictionary <string, int>(); foreach (var ReportFile in Delivery.Files) { //Get Columns var reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.Gzip), "$.columnHeaders[*].*"); using (reportReader) { int colIndex = 0; while (reportReader.Read()) { columns.Add(reportReader.Current.name, colIndex); colIndex++; } ///sssss } using (this.ImportManager = new GenericMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions() { MeasureOptions = MeasureOptions.IsBackOffice, MeasureOptionsOperator = OptionsOperator.Or, SegmentOptions = Data.Objects.SegmentOptions.All, SegmentOptionsOperator = OptionsOperator.And })) { this.ImportManager.BeginImport(this.Delivery); Dictionary <string, GenericMetricsUnit> data = new Dictionary <string, GenericMetricsUnit>(); // Checksums _isChecksum = true; reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.Gzip), "$.totalsForAllResults.*"); using (reportReader) { this.Mappings.OnFieldRequired = field => reportReader.Current[field]; if (reportReader.Read()) { GenericMetricsUnit checksumUnit = new GenericMetricsUnit(); metricsUnitMapping.Apply(checksumUnit); foreach (var m in checksumUnit.MeasureValues) { if (m.Key.Options.HasFlag(MeasureOptions.ValidationRequired)) { currentOutput.Checksum.Add(m.Key.Name, m.Value); } } } } _isChecksum = false; //Get Valuees reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.Gzip), "$.rows[*].*"); using (reportReader) { this.Mappings.OnFieldRequired = field => reportReader.Current["array"][columns[field]]; while (reportReader.Read()) { GenericMetricsUnit tempUnit = new GenericMetricsUnit(); metricsUnitMapping.Apply(tempUnit); SegmentObject tracker = tempUnit.SegmentDimensions[ImportManager.SegmentTypes[Segment.Common.Tracker]]; GenericMetricsUnit existingUnit = null; // check if we already found a metrics unit with the same tracker if (!data.TryGetValue(tracker.Value, out existingUnit)) { tempUnit.Output = currentOutput; data.Add(tracker.Value, tempUnit); } else { // if tracker already exists, merge with existing values foreach (var m in tempUnit.MeasureValues) { if (!m.Key.Options.HasFlag(MeasureOptions.IsBackOffice)) { continue; } existingUnit.MeasureValues[m.Key] += m.Value; } } } } // Import all unique units per tracker foreach (GenericMetricsUnit metricsUnit in data.Values) { this.ImportManager.ImportMetrics(metricsUnit); } ImportManager.EndImport(); } } return(Core.Services.ServiceOutcome.Success); }
protected override Core.Services.ServiceOutcome DoPipelineWork() { bool includeConversionTypes = Boolean.Parse(this.Delivery.Parameters["includeConversionTypes"].ToString()); bool includeDisplaytData = Boolean.Parse(this.Delivery.Parameters["includeDisplaytData"].ToString()); bool ConvertToUSD = Boolean.Parse(this.Delivery.Parameters["ConvertToUSD"].ToString()); //double ConstCurrencyRate = this.Delivery.Parameters.ContainsKey("ConstCurrencyRate") ? Convert.ToDouble(this.Delivery.Parameters["ConstCurrencyRate"]) : 1; //Status Members Dictionary <string, ObjectStatus> kwd_Status_Data = new Dictionary <string, ObjectStatus>(); Dictionary <string, ObjectStatus> placement_kwd_Status_Data = new Dictionary <string, ObjectStatus>(); Dictionary <Int64, ObjectStatus> adGroup_Status_Data = new Dictionary <Int64, ObjectStatus>(); Dictionary <Int64, ObjectStatus> ad_Status_Data = new Dictionary <Int64, ObjectStatus>(); Dictionary <Int64, ObjectStatus> campaign_Status_Data = new Dictionary <Int64, ObjectStatus>(); using (this.ImportManager = new AdMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions() { MeasureOptions = MeasureOptions.IsTarget | MeasureOptions.IsCalculated | MeasureOptions.IsBackOffice, MeasureOptionsOperator = OptionsOperator.Not, SegmentOptions = Data.Objects.SegmentOptions.All, SegmentOptionsOperator = OptionsOperator.And })) { string[] requiredHeaders = new string[1]; requiredHeaders[0] = Const.AdPreRequiredHeader; #region Getting Keywords Data Dictionary <string, double> _totals = new Dictionary <string, double>(); DeliveryFile _keyWordsFile = this.Delivery.Files[GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT]]; requiredHeaders[0] = Const.AdPreRequiredHeader; var _keywordsReader = new CsvDynamicReader(_keyWordsFile.OpenContents(compression: FileCompression.Gzip), requiredHeaders); _keywordsReader.MatchExactColumns = false; Dictionary <string, KeywordTarget> _keywordsData = new Dictionary <string, KeywordTarget>(); this.ImportManager.BeginImport(this.Delivery); using (_keywordsReader) { while (_keywordsReader.Read()) { this.Mappings.OnFieldRequired = field => _keywordsReader.Current[field]; if (_keywordsReader.Current[Const.KeywordIdFieldName] == Const.EOF) { break; } KeywordPrimaryKey keywordPrimaryKey = new KeywordPrimaryKey() { KeywordId = Convert.ToInt64(_keywordsReader.Current[Const.KeywordIdFieldName]), AdgroupId = Convert.ToInt64(_keywordsReader.Current[Const.AdGroupIdFieldName]), CampaignId = Convert.ToInt64(_keywordsReader.Current[Const.CampaignIdFieldName]) }; KeywordTarget keyword = new KeywordTarget() { OriginalID = _keywordsReader.Current[Const.KeywordIdFieldName], Keyword = _keywordsReader.Current[Const.KeywordFieldName], //Status = kwd_Status_Data[keywordPrimaryKey.ToString()] }; keyword.QualityScore = Convert.ToString(_keywordsReader.Current[Const.QualityScoreFieldName]); string matchType = _keywordsReader.Current[Const.MatchTypeFieldName]; keyword.MatchType = (KeywordMatchType)Enum.Parse(typeof(KeywordMatchType), matchType, true); //Setting Tracker for Keyword if (!String.IsNullOrWhiteSpace(Convert.ToString(_keywordsReader.Current[Const.DestUrlFieldName]))) { keyword.DestinationUrl = Convert.ToString(_keywordsReader.Current[Const.DestUrlFieldName]); //setting kwd tracker //if (((String)(_keywordsReader.Current[Const.DestUrlFieldName])).IndexOf(Const.CreativeIDTrackingValue, StringComparison.OrdinalIgnoreCase) >= 0) if (Convert.ToBoolean(this.Delivery.Parameters["UseKwdTrackerAsAdTracker"])) { if (this.Mappings != null && this.Mappings.Objects.ContainsKey(typeof(KeywordTarget))) { this.Mappings.Objects[typeof(KeywordTarget)].Apply(keyword); } } } _keywordsData.Add(keywordPrimaryKey.ToString(), keyword); } } #endregion Dictionary <string, PlacementTarget> _placementsData = new Dictionary <string, PlacementTarget>(); #region Getting Placements Data string[] _placementsFileRequiredHeaders = new string[1]; _placementsFileRequiredHeaders[0] = Const.PlacementCriteriaID; DeliveryFile _PlacementsFile = this.Delivery.Files[GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.PLACEMENT_PERFORMANCE_REPORT]]; var _PlacementsReader = new CsvDynamicReader(_PlacementsFile.OpenContents(compression: FileCompression.Gzip), _placementsFileRequiredHeaders); using (_PlacementsReader) { while (_PlacementsReader.Read()) { if (_PlacementsReader.Current[Const.PlacementCriteriaID] == Const.EOF) { break; } //Read data only if managed GDN, otherwise it is an automatic GDN so skip if (!((String)(_PlacementsReader.Current[Const.PlacementCriteriaID])).Trim().Equals("--")) { KeywordPrimaryKey placementPrimaryKey = new KeywordPrimaryKey() { KeywordId = Convert.ToInt64(_PlacementsReader.Current[Const.PlacementCriteriaID]), AdgroupId = Convert.ToInt64(_PlacementsReader.Current[Const.AdGroupIdFieldName]), CampaignId = Convert.ToInt64(_PlacementsReader.Current[Const.CampaignIdFieldName]) }; PlacementTarget placement = new PlacementTarget() { OriginalID = _PlacementsReader.Current[Const.PlacementCriteriaID], Placement = _PlacementsReader.Current[Const.PlacementFieldName], PlacementType = PlacementType.Managed, // Status = placement_kwd_Status_Data[placementPrimaryKey.ToString()] }; //Setting Tracker for placment if (!String.IsNullOrWhiteSpace(Convert.ToString(_PlacementsReader.Current[Const.DestUrlFieldName]))) { placement.DestinationUrl = Convert.ToString(_PlacementsReader.Current[Const.DestUrlFieldName]); } _placementsData.Add(placementPrimaryKey.ToString(), placement); } } } #endregion #region Getting Conversions Data //Get Ads Conversion ( for ex. signup , purchase ) DeliveryFile _conversionFile = this.Delivery.Files[GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT] + "_Conv"]; var _conversionsReader = new CsvDynamicReader(_conversionFile.OpenContents(compression: FileCompression.Gzip), requiredHeaders); Dictionary <string, Dictionary <string, long> > importedAdsWithConv = new Dictionary <string, Dictionary <string, long> >(); using (_conversionsReader) { while (_conversionsReader.Read()) { if (_conversionsReader.Current[Const.AdIDFieldName] == Const.EOF) // if end of report { break; } string conversionKey = String.Format("{0}#{1}", _conversionsReader.Current[Const.AdIDFieldName], _conversionsReader.Current[Const.KeywordIdFieldName]); Dictionary <string, long> conversionDic = new Dictionary <string, long>(); if (!importedAdsWithConv.TryGetValue(conversionKey, out conversionDic)) { //ADD conversionKey to importedAdsWithConv //than add conversion field to importedAdsWithConv : <conversion name , conversion value> Dictionary <string, long> conversion = new Dictionary <string, long>(); conversion.Add(Convert.ToString(_conversionsReader.Current[Const.ConversionTrackingPurposeFieldName]), Convert.ToInt64(_conversionsReader.Current[Const.ConversionManyPerClickFieldName])); importedAdsWithConv.Add(conversionKey, conversion); } else // if Key exists { // if current add already has current conversion type than add value to the current type if (!conversionDic.ContainsKey(Convert.ToString(_conversionsReader.Current[Const.ConversionTrackingPurposeFieldName]))) { conversionDic.Add(Convert.ToString(_conversionsReader.Current[Const.ConversionTrackingPurposeFieldName]), Convert.ToInt64(_conversionsReader.Current[Const.ConversionManyPerClickFieldName])); } // else create new conversion type and add the value else { conversionDic[Convert.ToString(_conversionsReader.Current[Const.ConversionTrackingPurposeFieldName])] += Convert.ToInt64(_conversionsReader.Current[Const.ConversionManyPerClickFieldName]); } } } } #endregion #region Getting Ads Data DeliveryFile _adPerformanceFile = this.Delivery.Files[GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.AD_PERFORMANCE_REPORT]]; var _adsReader = new CsvDynamicReader(_adPerformanceFile.OpenContents(compression: FileCompression.Gzip), requiredHeaders); Dictionary <string, Ad> importedAds = new Dictionary <string, Ad>(); //session.Begin(false); //this.ImportManager.BeginImport(this.Delivery); DeliveryOutput currentOutput = Delivery.Outputs.First(); foreach (KeyValuePair <string, Measure> measure in this.ImportManager.Measures) { if (measure.Value.Options.HasFlag(MeasureOptions.ValidationRequired)) { _totals.Add(measure.Key, 0); } } using (_adsReader) { this.Mappings.OnFieldRequired = field => _adsReader.Current[field]; while (_adsReader.Read()) { string currencyCode = ((string)(_adsReader.Current.Currency)).ToUpper(); // Adding totals line for validation (checksum) if (_adsReader.Current[Const.AdIDFieldName] == Const.EOF) { foreach (KeyValuePair <string, Measure> measure in this.ImportManager.Measures) { if (!measure.Value.Options.HasFlag(MeasureOptions.ValidationRequired)) { continue; } switch (measure.Key) { case Measure.Common.Clicks: _totals[Measure.Common.Clicks] = Convert.ToInt64(_adsReader.Current.Clicks); break; case Measure.Common.Cost: _totals[Measure.Common.Cost] = ConvertToUSD ? this.ConvertToUSD(this.Delivery.Parameters["CurrencyCode"].ToString().ToUpper(), (Convert.ToDouble(_adsReader.Current.Cost)) / 1000000) : (Convert.ToDouble(_adsReader.Current.Cost)) / 1000000; break; case Measure.Common.Impressions: _totals[Measure.Common.Impressions] = Convert.ToInt64(_adsReader.Current.Impressions); break; } } break; } AdMetricsUnit adMetricsUnit = new AdMetricsUnit(); adMetricsUnit.Output = currentOutput; Ad ad; #region Try Get SearchKWD /***********************************************************************************/ //Creating kwd primary key KeywordPrimaryKey kwdKey = new KeywordPrimaryKey() { AdgroupId = Convert.ToInt64(_adsReader.Current[Const.AdGroupIdFieldName]), KeywordId = Convert.ToInt64(_adsReader.Current[Const.KeywordIdFieldName]), CampaignId = Convert.ToInt64(_adsReader.Current[Const.CampaignIdFieldName]) }; //Check if keyword file contains this kwdkey and not a GDN Keyword String[] GdnKwdIds = this.Delivery.Parameters["KeywordContentId"].ToString().Split(','); bool IsSearchKwd = false; KeywordTarget kwd = null; PlacementTarget placement = null; if (!GdnKwdIds.Contains(kwdKey.KeywordId.ToString()) && _keywordsData.ContainsKey(kwdKey.ToString())) { kwd = new KeywordTarget(); try { kwd = _keywordsData[kwdKey.ToString()]; } catch (Exception) { //Creating KWD with OriginalID , since the KWD doesnt exists in KWD report. kwd = new KeywordTarget { OriginalID = Convert.ToString(_adsReader.Current[Const.KeywordIdFieldName]) }; } IsSearchKwd = true; } else { placement = new PlacementTarget(); try { placement = _placementsData[kwdKey.ToString()]; } catch (Exception) { placement.OriginalID = Convert.ToString(_adsReader.Current[Const.KeywordIdFieldName]); placement.PlacementType = PlacementType.Automatic; placement.Placement = Const.AutoDisplayNetworkName; } } /***********************************************************************************/ #endregion string adId = _adsReader.Current[Const.AdIDFieldName]; if (!importedAds.ContainsKey(adId)) { ad = new Ad(); ad.OriginalID = adId; ad.Channel = new Channel() { ID = 1 }; ad.Account = new Account { ID = this.Delivery.Account.ID, OriginalID = (String)_adPerformanceFile.Parameters["AdwordsClientID"] }; // ad.Status = ad_Status_Data[Convert.ToInt64(adId)]; #region Ad Type /****************************************************************/ string adTypeColumnValue = Convert.ToString(_adsReader.Current[Const.AdTypeFieldName]); string devicePreferenceColumnValue = Convert.ToString(_adsReader.Current[Const.AdDevicePreferenceFieldName]); if (!GoogleAdTypeDic.ContainsKey(adTypeColumnValue)) { continue; } string adTypeEdgeValue = GoogleAdTypeDic[adTypeColumnValue].ToString(); //EdgeAdType atv = (EdgeAdType)Enum.Parse(typeof(EdgeAdType), adTypeEdgeValue, true); //is mobile ad ? if (devicePreferenceColumnValue.Equals(Const.AdDevicePreferenceMobileFieldValue)) { string mobileValue = string.Format("Mobile {0}", Convert.ToString(_adsReader.Current[Const.AdTypeFieldName])); //Check if this mobile value exists on dictionary if (GoogleAdTypeDic.ContainsKey(mobileValue)) { adTypeEdgeValue = GoogleAdTypeDic[mobileValue].ToString(); } else { adTypeEdgeValue = GoogleAdTypeDic[Const.AdTypeValues.Mobile_ad].ToString(); } } ad.ExtraFields[AdType] = (int)(EdgeAdType)Enum.Parse(typeof(EdgeAdType), adTypeEdgeValue, true);; /****************************************************************/ #endregion //Creative ad.Creatives.Add(new TextCreative { TextType = TextCreativeType.DisplayUrl, Text = _adsReader.Current[Const.DisplayURLFieldName] }); #region Ad Tracker segment /******************************************************/ ////Setting Tracker for Ad if (!String.IsNullOrWhiteSpace(_adsReader.Current[Const.DestUrlFieldName])) { ad.DestinationUrl = _adsReader.Current[Const.DestUrlFieldName]; if (this.Mappings != null && this.Mappings.Objects.ContainsKey(typeof(Ad))) { this.Mappings.Objects[typeof(Ad)].Apply(ad); } } //if Ad doesnt contains tracker than check for kwd tracker if (Convert.ToBoolean(this.Delivery.Parameters["UseKwdTrackerAsAdTracker"])) { if (kwd != null && kwd.Segments != null && kwd.Segments.ContainsKey(this.ImportManager.SegmentTypes[Segment.Common.Tracker])) { if (kwd.Segments[this.ImportManager.SegmentTypes[Segment.Common.Tracker]] != null && kwd.Segments[this.ImportManager.SegmentTypes[Segment.Common.Tracker]].Value != null) { SegmentObject tracker = kwd.Segments[this.ImportManager.SegmentTypes[Segment.Common.Tracker]]; //if value contains ADID than replace ADID with AD original id tracker.Value = tracker.Value.Replace("ADID", ad.OriginalID); ad.Segments[this.ImportManager.SegmentTypes[Segment.Common.Tracker]] = tracker; } } } /******************************************************/ #endregion #region Campaign /****************************************************************/ ad.Segments[this.ImportManager.SegmentTypes[Segment.Common.Campaign]] = new Campaign() { OriginalID = _adsReader.Current[Const.CampaignIdFieldName], Name = _adsReader.Current[Const.CampaignFieldName], //Status = campaign_Status_Data[Convert.ToInt64(_adsReader.Current[Const.CampaignIdFieldName])] }; /****************************************************************/ #endregion #region Image /****************************************************************/ //Image Type > Create Image if (String.Equals(Convert.ToString(_adsReader.Current[Const.AdTypeFieldName]), "Image ad")) { string adNameField = _adsReader.Current[Const.AdFieldName]; string[] imageParams = adNameField.Trim().Split(new Char[] { ':', ';' }); // Ad name: 468_60_Test7options_Romanian.swf; 468 x 60 ad.Name = imageParams[1].Trim(); ad.Creatives.Add(new ImageCreative() { ImageUrl = imageParams[1].Trim(), ImageSize = imageParams[2].Trim() }); } /****************************************************************/ #endregion #region Text od Display /****************************************************************/ else //Text ad or Display ad { ad.Name = _adsReader.Current[Const.AdFieldName]; ad.Creatives.Add(new TextCreative { TextType = TextCreativeType.Title, Text = _adsReader.Current.Ad, }); ad.Creatives.Add(new TextCreative { TextType = TextCreativeType.Body, Text = _adsReader.Current["Description line 1"], Text2 = _adsReader.Current["Description line 2"] }); } /****************************************************************/ #endregion #region Adgroup /****************************************************************/ //Insert Adgroup ad.Segments[this.ImportManager.SegmentTypes[Segment.Common.AdGroup]] = new AdGroup() { Campaign = (Campaign)ad.Segments[this.ImportManager.SegmentTypes[Segment.Common.Campaign]], Value = _adsReader.Current[Const.AdGroupFieldName], OriginalID = _adsReader.Current[Const.AdGroupIdFieldName], // Status = adGroup_Status_Data[Convert.ToInt64(_adsReader.Current[Const.AdGroupIdFieldName])] }; /****************************************************************/ #endregion #region Network /****************************************************************/ //Insert Network Type Display Network / Search Network //string networkType = Convert.ToString(_adsReader.Current[Const.NetworkFieldName]); //if (networkType.Equals(Const.GoogleSearchNetwork)) // networkType = Const.SystemSearchNetwork; //else if (networkType.Equals(Const.GoogleDisplayNetwork)) // networkType = Const.SystemDisplayNetwork; //ad.ExtraFields[NetworkType] = networkType; /****************************************************************/ #endregion importedAds.Add(adId, ad); this.ImportManager.ImportAd(ad); } else { ad = importedAds[adId]; } adMetricsUnit.Ad = ad; //INSERTING SEARCH KEYWORD INTO METRICS if (IsSearchKwd & kwd != null) { adMetricsUnit.TargetDimensions = new List <Target>(); adMetricsUnit.TargetDimensions.Add(kwd); } //INSERTING GDN KEYWORD INTO METRICS else if (placement != null) { //INSERTING KEYWORD INTO METRICS adMetricsUnit.TargetDimensions = new List <Target>(); adMetricsUnit.TargetDimensions.Add(placement); } //INSERTING METRICS DATA adMetricsUnit.MeasureValues = new Dictionary <Measure, double>(); adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Clicks], Convert.ToInt64(_adsReader.Current.Clicks)); //Currencies Conversion Support adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Cost], ConvertToUSD ? this.ConvertToUSD(currencyCode.ToUpper(), (Convert.ToDouble(_adsReader.Current.Cost)) / 1000000) : (Convert.ToDouble(_adsReader.Current.Cost)) / 1000000); if (ConvertToUSD) { adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.CostBeforeConversion], (Convert.ToDouble(_adsReader.Current.Cost)) / 1000000); adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.USDConversionRate], Convert.ToDouble(this.ImportManager.CurrencyRates[currencyCode].RateValue)); } adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Impressions], Convert.ToInt64(_adsReader.Current.Impressions)); adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.AveragePosition], Convert.ToDouble(_adsReader.Current[Const.AvgPositionFieldName])); adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[GoogleMeasuresDic[Const.ConversionOnePerClickFieldName]], Convert.ToDouble(_adsReader.Current[Const.ConversionOnePerClickFieldName])); adMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[GoogleMeasuresDic[Const.ConversionManyPerClickFieldName]], Convert.ToDouble(_adsReader.Current[Const.ConversionManyPerClickFieldName])); //Inserting conversion values string conversionKey = String.Format("{0}#{1}", ad.OriginalID, _adsReader.Current[Const.KeywordIdFieldName]); Dictionary <string, long> conversionDic = new Dictionary <string, long>(); if (importedAdsWithConv.TryGetValue(conversionKey, out conversionDic)) { foreach (var pair in conversionDic) { if (GoogleMeasuresDic.ContainsKey(pair.Key)) { adMetricsUnit.MeasureValues[this.ImportManager.Measures[GoogleMeasuresDic[pair.Key]]] = pair.Value; } } } adMetricsUnit.Currency = new Currency { Code = Convert.ToString(_adsReader.Current.Currency) }; this.ImportManager.ImportMetrics(adMetricsUnit); } #endregion } #region Getting Sitelinks Data without metrics if (this.Delivery.Parameters.ContainsKey("AppendSitelinks") && Boolean.Parse(this.Delivery.Parameters["AppendSitelinks"].ToString())) { string[] sitelinksRequiredHeaders = new string[1]; sitelinksRequiredHeaders[0] = Const.PlaceholderFeedItemID; DeliveryFile _sitelinkPerformanceFile = this.Delivery.Files[GoogleStaticReportsNamesUtill._reportNames[GA.ReportDefinitionReportType.PLACEHOLDER_FEED_ITEM_REPORT]]; var _sitelinkReader = new CsvDynamicReader(_sitelinkPerformanceFile.OpenContents(compression: FileCompression.Gzip), sitelinksRequiredHeaders); AdMetricsUnit siteLinkMetricsUnit = new AdMetricsUnit(); siteLinkMetricsUnit.Output = currentOutput; Ad sitelinkAd; using (_sitelinkReader) { this.Mappings.OnFieldRequired = field => _sitelinkReader.Current[field]; //to do : get site link tracker string[] sitelinkAttr; while (_sitelinkReader.Read()) { if (((String)_sitelinkReader.Current[Const.SiteLinkAttributeValuesHeader]).Equals(Const.Sitelink_EOF)) { break; } string sitelinkId = string.Format("{0}{1}{2}", _sitelinkReader.Current[Const.PlaceholderFeedItemID], _sitelinkReader.Current[Const.CampaignIdFieldName], _sitelinkReader.Current[Const.AdGroupIdFieldName]); sitelinkAd = new Ad(); sitelinkAd.OriginalID = sitelinkId; sitelinkAd.Channel = new Channel() { ID = 1 }; sitelinkAd.Account = new Account { ID = this.Delivery.Account.ID, OriginalID = (String)_adPerformanceFile.Parameters["AdwordsClientID"] }; //Creative sitelinkAttr = ((String)_sitelinkReader.Current[Const.SiteLinkAttributeValuesHeader]).Split(';'); bool legacy = sitelinkAttr.Count() != 4 ? true : false; string destUrl = string.Empty; bool destUrlParsingError = false; //Checking desturl errors ( we would like to insert only sitelinks that contains desturl ). try { destUrl = sitelinkAttr[1]; } catch (Exception e) { Log.Write("Error while trying to pars destination url from attribute field on sitelink report", e); destUrlParsingError = true; } if (!destUrlParsingError) { ////Setting Tracker for Ad if (!String.IsNullOrWhiteSpace(sitelinkAttr[1])) { sitelinkAd.DestinationUrl = sitelinkAttr[1]; if (this.Mappings != null && this.Mappings.Objects.ContainsKey(typeof(Ad))) { this.Mappings.Objects[typeof(Ad)].Apply(sitelinkAd); } } sitelinkAd.Segments[this.ImportManager.SegmentTypes[Segment.Common.Campaign]] = new Campaign() { OriginalID = _sitelinkReader.Current[Const.CampaignIdFieldName], Name = _sitelinkReader.Current[Const.CampaignFieldName], }; //Insert Adgroup sitelinkAd.Segments[this.ImportManager.SegmentTypes[Segment.Common.AdGroup]] = new AdGroup() { Campaign = (Campaign)sitelinkAd.Segments[this.ImportManager.SegmentTypes[Segment.Common.Campaign]], Value = _sitelinkReader.Current[Const.AdGroupFieldName], OriginalID = _sitelinkReader.Current[Const.AdGroupIdFieldName], // Status = adGroup_Status_Data[Convert.ToInt64(_adsReader.Current[Const.AdGroupIdFieldName])] }; sitelinkAd.Creatives.Add(new TextCreative { TextType = TextCreativeType.DisplayUrl, Text = sitelinkAttr[1] }); if (!legacy) // only in case it doesnt contains legacy siteink { sitelinkAd.Creatives.Add(new TextCreative { TextType = TextCreativeType.Body, Text = sitelinkAttr[2], Text2 = sitelinkAttr[3] }); } sitelinkAd.Name = "[Sitelink] " + sitelinkAttr[0]; sitelinkAd.Creatives.Add(new TextCreative { TextType = TextCreativeType.Title, Text = "[Sitelink] " + sitelinkAttr[0] }); //Ad Type //Note: changed to "sitelink" following Amir request sitelinkAd.ExtraFields[AdType] = (int)(EdgeAdType.Sitelink); siteLinkMetricsUnit.Ad = sitelinkAd; //Setting Default Currency as USD following Amir's request from March 2014 siteLinkMetricsUnit.Currency = new Currency { Code = "USD" }; //INSERTING METRICS DATA siteLinkMetricsUnit.MeasureValues = new Dictionary <Measure, double>(); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Clicks], 0); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Cost], 0); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.Impressions], 0); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[Measure.Common.AveragePosition], 0); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[GoogleMeasuresDic[Const.ConversionOnePerClickFieldName]], 0); siteLinkMetricsUnit.MeasureValues.Add(this.ImportManager.Measures[GoogleMeasuresDic[Const.ConversionManyPerClickFieldName]], 0); ImportManager.ImportMetrics(siteLinkMetricsUnit); ImportManager.ImportAd(sitelinkAd); } } } }// end if #endregion currentOutput.Checksum = _totals; this.ImportManager.EndImport(); } return(Core.Services.ServiceOutcome.Success); }
/// <summary> /// Очищает данный сегмент сетки /// </summary> public void ClearSegment() { isFree = true; occupiedObject = null; }
/// <summary> /// Поиск новой точки, в которую может переместиться игрок /// </summary> private Point GetNewPlayerPosition(Point curPlayerPosition, Enumerators.Control.SwipeDirection swipeDirection, bool collectBonuses = true) { if (currentGridSegmentWithPlayer != null) { Point dir = null; var grid = GameManager.Source.GridManager.GridSegments; // Определяет количество клеток на сетке в выбранном направлении int iterCount = 0; int high = grid.GetLength(0) - 1; switch (swipeDirection) { case Enumerators.Control.SwipeDirection.Left: dir = new Point(0, -1); iterCount = curPlayerPosition.Y; break; case Enumerators.Control.SwipeDirection.Right: dir = new Point(0, 1); iterCount = high - curPlayerPosition.Y; break; case Enumerators.Control.SwipeDirection.Down: dir = new Point(1, 0); iterCount = high - curPlayerPosition.X; break; case Enumerators.Control.SwipeDirection.Up: dir = new Point(-1, 0); iterCount = curPlayerPosition.X; break; } Point curr = curPlayerPosition; int emptyCount = 0; for (int i = 0; i < iterCount; i++) { Point next = new Point(curr.X + dir.X, curr.Y + dir.Y); SegmentObject obj = grid[next.X, next.Y].OccupiedObject; if (obj != null) { if (obj.Type == Enumerators.Game.SegmentObjectType.NotDraggable) { break; } else if (obj.Type == Enumerators.Game.SegmentObjectType.Draggable) { segmentObjects.Add(obj); } } else { if (collectBonuses) { if (grid[next.X, next.Y].ContainsBonus) { gridSegmentsWithBonus.Add(grid[next.X, next.Y]); } } emptyCount++; } curr = next; } curr = new Point(curPlayerPosition.X + (dir.X * emptyCount), curPlayerPosition.Y + (dir.Y * emptyCount)); for (int i = 0; i < segmentObjects.Count; i++) { if (i == 0) { segmentPositions.Add(curr); } else { Point newPoint = new Point(curr.X + (dir.X * i), curr.Y + (dir.Y * i)); segmentPositions.Add(newPoint); } } return(emptyCount > 0 ? curr : null); } return(null); }
protected override Core.Services.ServiceOutcome DoPipelineWork() { MappingContainer metricsUnitMapping; if (!this.Mappings.Objects.TryGetValue(typeof(GenericMetricsUnit), out metricsUnitMapping)) { throw new MappingConfigurationException("Missing mapping definition for GenericMetricsUnit."); } currentOutput = this.Delivery.Outputs.First(); currentOutput.Checksum = new Dictionary <string, double>(); Dictionary <string, int> columns = new Dictionary <string, int>(); using (this.ImportManager = new GenericMetricsImportManager(this.Instance.InstanceID, new MetricsImportManagerOptions() { MeasureOptions = MeasureOptions.IsBackOffice, MeasureOptionsOperator = OptionsOperator.Or, SegmentOptions = Data.Objects.SegmentOptions.All, SegmentOptionsOperator = OptionsOperator.And })) { this.ImportManager.BeginImport(this.Delivery); Dictionary <string, GenericMetricsUnit> data = new Dictionary <string, GenericMetricsUnit>(); foreach (var ReportFile in Delivery.Files) { //check number of recordes JsonDynamicReader reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.None), "$.totalSize"); int numOfRecordes = 0; if (reportReader.Read()) { numOfRecordes = int.Parse(reportReader.Current.totalSize); } reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.None), "$.nextRecordsUrl"); if (reportReader.Read()) { Log.Write(string.Format("Salesforce Attention - account {0} contains more than 1 file per query {1}", this.Delivery.Account.ID, ReportFile.Parameters["Query"].ToString()), LogMessageType.Warning); } if (numOfRecordes > 0) { //Get Values reportReader = new JsonDynamicReader(ReportFile.OpenContents(compression: FileCompression.None), "$.records[*].*"); using (reportReader) { this.Mappings.OnFieldRequired = field => { object value = new object(); string[] nestedFields; try { if (field.Contains('.')) { nestedFields = field.Split('.'); value = reportReader.Current[nestedFields[0]]; foreach (var item in nestedFields) { if (item.Equals(nestedFields[0])) { continue; } value = ((Dictionary <string, object>)value)[item]; } value = reportReader.Current[nestedFields[0]][nestedFields[1]]; Console.Write(value.ToString()); return(value); } else { Console.Write(value.ToString()); return(reportReader.Current[field]); } } catch (Exception ex) { throw new Exception(string.Format("Error while trying to map field {0} from mapper", field), ex); } }; while (reportReader.Read()) { GenericMetricsUnit metricsUnit = new GenericMetricsUnit(); metricsUnitMapping.Apply(metricsUnit); if (metricsUnit.MeasureValues != null) { SegmentObject tracker = metricsUnit.SegmentDimensions[ImportManager.SegmentTypes[Segment.Common.Tracker]]; GenericMetricsUnit importedUnit = null; // check if we already found a metrics unit with the same tracker if (!data.TryGetValue(tracker.Value, out importedUnit)) { metricsUnit.Output = currentOutput; data.Add(tracker.Value, metricsUnit); } else //Tracker already exists { // Merge captured measure with existing measures foreach (var capturedMeasure in metricsUnit.MeasureValues) { if (!capturedMeasure.Key.Options.HasFlag(MeasureOptions.IsBackOffice)) { continue; } //Measure already exists per tracker than aggregate: if (importedUnit.MeasureValues.ContainsKey(capturedMeasure.Key)) { importedUnit.MeasureValues[capturedMeasure.Key] += capturedMeasure.Value; } else { //Captured Measure doest exists with this tracker: importedUnit.MeasureValues.Add(capturedMeasure.Key, capturedMeasure.Value); } } } #region Validation // For validations foreach (var m in metricsUnit.MeasureValues) { if (m.Key.Options.HasFlag(MeasureOptions.ValidationRequired)) { if (!currentOutput.Checksum.ContainsKey(m.Key.Name)) { currentOutput.Checksum.Add(m.Key.Name, m.Value); } else { currentOutput.Checksum[m.Key.Name] += m.Value; } } } #endregion } } } } else { Log.Write("No Records Found in File " + ReportFile.Name, LogMessageType.Information); } } // Import all unique units per tracker foreach (GenericMetricsUnit metricsUnit in data.Values) { this.ImportManager.ImportMetrics(metricsUnit); } ImportManager.EndImport(); } return(Core.Services.ServiceOutcome.Success); }