public RootObject(UserData userData, InvData invData) { UserData = userData; Stats = new StatData(); ModData = new ModData(); Activity = new CountData(); }
public SegmentCountInfo(ITranslationOrigin translationOrigin, CountData countData, bool isLocked, int spaceCount) { TranslationOrigin = translationOrigin; CountData = countData; IsLocked = isLocked; SpaceCount = spaceCount; }
public void Increment(string key, CountData countData) { Contract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(key)); Contract.Requires <ArgumentNullException>(countData != null); info[key].Increment(countData); }
/// <summary> /// 写入字节流(简版) /// </summary> protected override void toWriteBytesSimple(BytesWriteStream stream) { stream.writeInt(this.id); stream.writeInt(this.price); if (this.days != null) { stream.writeLen(this.days.size()); if (!this.days.isEmpty()) { CountData[] daysVValues = this.days.getValues(); int daysVMark = this.days.getMark(); int daysVStart = this.days.getStart(); for (int daysVI = 0, daysVLen = this.days.length(); daysVI < daysVLen; ++daysVI) { CountData daysV = daysVValues[(daysVI + daysVStart) & daysVMark]; if (daysV != null) { stream.writeDataSimpleNotNull(daysV); } else { nullObjError("daysV"); } } } } else { nullObjError("days"); } }
/// <summary> /// 复制(深拷贝) /// </summary> protected override void toCopy(BaseData data) { if (!(data is AuctionItemRecordData)) { return; } AuctionItemRecordData mData = (AuctionItemRecordData)data; this.id = mData.id; this.price = mData.price; if (mData.days != null) { if (this.days != null) { this.days.clear(); this.days.ensureCapacity(mData.days.size()); } else { this.days = new SQueue <CountData>(); } SQueue <CountData> daysT = this.days; if (!mData.days.isEmpty()) { CountData[] daysVValues = mData.days.getValues(); int daysVMark = mData.days.getMark(); int daysVStart = mData.days.getStart(); for (int daysVI = 0, daysVLen = mData.days.length(); daysVI < daysVLen; ++daysVI) { CountData daysV = daysVValues[(daysVI + daysVStart) & daysVMark]; CountData daysU; if (daysV != null) { daysU = (CountData)daysV.clone(); } else { daysU = null; nullObjError("daysU"); } daysT.offer(daysU); } } } else { this.days = null; nullObjError("days"); } }
/// <summary> /// 转文本输出 /// </summary> protected override void toWriteDataString(DataWriter writer) { writer.writeTabs(); writer.sb.Append("id"); writer.sb.Append(':'); writer.sb.Append(this.id); writer.writeEnter(); writer.writeTabs(); writer.sb.Append("price"); writer.sb.Append(':'); writer.sb.Append(this.price); writer.writeEnter(); writer.writeTabs(); writer.sb.Append("days"); writer.sb.Append(':'); writer.sb.Append("Queue<CountData>"); if (this.days != null) { SQueue <CountData> daysT = this.days; int daysLen = daysT.size(); writer.sb.Append('('); writer.sb.Append(daysLen); writer.sb.Append(')'); writer.writeEnter(); writer.writeLeftBrace(); for (int daysI = 0; daysI < daysLen; ++daysI) { CountData daysV = daysT.get(daysI); writer.writeTabs(); writer.sb.Append(daysI); writer.sb.Append(':'); if (daysV != null) { daysV.writeDataString(writer); } else { writer.sb.Append("CountData=null"); } writer.writeEnter(); } writer.writeRightBrace(); } else { writer.sb.Append("=null"); } writer.writeEnter(); }
/// <summary> /// 复制(潜拷贝) /// </summary> protected override void toShadowCopy(BaseData data) { if (!(data is CountData)) { return; } CountData mData = (CountData)data; this.num = mData.num; this.total = mData.total; }
/// <summary> /// 读取字节流(完整版) /// </summary> protected override void toReadBytesFull(BytesReadStream stream) { stream.startReadObj(); this.id = stream.readInt(); this.price = stream.readInt(); int daysLen = stream.readLen(); if (this.days != null) { this.days.clear(); this.days.ensureCapacity(daysLen); } else { this.days = new SQueue <CountData>(); } SQueue <CountData> daysT = this.days; for (int daysI = daysLen - 1; daysI >= 0; --daysI) { CountData daysV; BaseData daysVT = stream.readDataFullNotNull(); if (daysVT != null) { if (daysVT is CountData) { daysV = (CountData)daysVT; } else { daysV = new CountData(); if (!(daysVT.GetType().IsAssignableFrom(typeof(CountData)))) { stream.throwTypeReadError(typeof(CountData), daysVT.GetType()); } daysV.shadowCopy(daysVT); } } else { daysV = null; } daysT.offer(daysV); } stream.endReadObj(); }
public void Check_If_400_Fields_Is_Created_In_GameLogic() { //Arrange GameLogic gl = GameLogic.Getinstance(); CountData ct = CountData.Getinstance(); int expected = 400; //Act gl.StartGame(10, 10, 10); int methodToTest = ct.CountFields(); //Assert Assert.AreEqual(expected, methodToTest); }
public async Task Increment_IncrementsData_ByExpectedValue(int incrementationAmount) { var beforeCount = await CountData.GetCount(); var promise = new TaskCompletionSource <int>(); lock (Tracker.emptyLock) { Tracker.Increment(incrementationAmount); UpdatesEmitter.OnStarIncrementationEventEmitted += amount => promise.SetResult(amount); } await promise.Task; Assert.AreEqual(beforeCount + incrementationAmount, await CountData.GetCount()); }
public void CreateAggregationData() { IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>() { -1.0, 0.0, 1.0 }); List <MutableAggregation> mutableAggregations = new List <MutableAggregation>() { MutableCount.Create(), MutableMean.Create(), MutableDistribution.Create(bucketBoundaries) }; List <IAggregationData> aggregates = new List <IAggregationData> { MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_DOUBLE), MutableViewData.CreateAggregationData(MutableSum.Create(), MEASURE_LONG), MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_DOUBLE), MutableViewData.CreateAggregationData(MutableLastValue.Create(), MEASURE_LONG) }; foreach (MutableAggregation mutableAggregation in mutableAggregations) { aggregates.Add(MutableViewData.CreateAggregationData(mutableAggregation, MEASURE_DOUBLE)); } List <IAggregationData> expected = new List <IAggregationData>() { SumDataDouble.Create(0), SumDataLong.Create(0), LastValueDataDouble.Create(double.NaN), LastValueDataLong.Create(0), CountData.Create(0), MeanData.Create(0, 0, double.MaxValue, double.MinValue), DistributionData.Create( 0, 0, double.PositiveInfinity, double.NegativeInfinity, 0, new List <long>() { 0L, 0L, 0L, 0L }) }; Assert.Equal(expected, aggregates); }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { CountData mData = (CountData)data; if (this.num != mData.num) { return(false); } if (this.total != mData.total) { return(false); } return(true); }
/// <summary> /// 设置计数值 /// </summary> /// <param name="tm"></param> /// <param name="data"></param> internal void SetValue(long tm, CountData data) { LastCall = data.End; Count += 1; UnitCount += 1; LastTime = tm; TotalTime += tm; if (MaxTime == 0 || MaxTime < tm) { MaxTime = tm; } if (MinTime == 0 || MinTime > tm) { MinTime = tm; } switch (data.Status) { case OperatorStatus.Success: break; case OperatorStatus.Unavailable: case OperatorStatus.NotFind: case OperatorStatus.DenyAccess: Deny += 1; break; case OperatorStatus.FormalError: FormalError += 1; break; case OperatorStatus.LocalException: case OperatorStatus.LogicalError: Bug += 1; break; default: Error += 1; break; } if (tm > 20000000) { TimeOut += 1; } }
private SegmentCountInfo CreateSegmentCountInfo(CountData countdata, bool isRepeated = false, byte matchPercent = 0) { var countData = countdata; var transOrigin = Substitute.For <ITranslationOrigin>(); if (isRepeated) { transOrigin.IsRepeated.Returns(true); } transOrigin.MatchPercent = matchPercent; return(new SegmentCountInfo(transOrigin, countData, false, 0)); }
public void PreventAggregationAndAggregationDataMismatch_Distribution_Count() { var tagValues1 = TagValues.Create(new List <ITagValue>() { V1, V2 }); var tagValues2 = TagValues.Create(new List <ITagValue>() { V10, V20 }); Dictionary <TagValues, IAggregationData> entries = new Dictionary <TagValues, IAggregationData>() { { tagValues1, DistributionData.Create(1, 1, 1, 1, 0, new List <long>() { 0L, 1L, 0L }) }, { tagValues2, CountData.Create(100) } }; AggregationAndAggregationDataMismatch(CreateView(DISTRIBUTION), entries); }
public void Increment(string key, CountData countData) { info[key].Increment(countData); }
public async Task GetCount_ReturnsAmount_OfCorrectValue() { var count = await Tracker.GetCount(); Assert.AreEqual(await CountData.GetCount(), count); }
/// <summary> /// 是否数据一致 /// </summary> protected override bool toDataEquals(BaseData data) { AuctionItemRecordData mData = (AuctionItemRecordData)data; if (this.id != mData.id) { return(false); } if (this.price != mData.price) { return(false); } if (mData.days != null) { if (this.days == null) { return(false); } if (this.days.size() != mData.days.size()) { return(false); } SQueue <CountData> daysT = this.days; SQueue <CountData> daysR = mData.days; int daysLen = daysT.size(); for (int daysI = 0; daysI < daysLen; ++daysI) { CountData daysU = daysT.get(daysI); CountData daysV = daysR.get(daysI); if (daysV != null) { if (daysU == null) { return(false); } if (!daysU.dataEquals(daysV)) { return(false); } } else { if (daysU != null) { return(false); } } } } else { if (this.days != null) { return(false); } } return(true); }
protected void ParseResponseSection(CountData countData) { countData.quoteCount = _rdr.ReadInt16(); // guessing 64.000 quotes should be enough in one response, the documentation will have the type }
private double GetPrice(string category, CountData countData) { return(GetPricePerWord(category) * countData.Words); }
private void ResetCount() { counts_ = new CountData(); }
public void GetMetricSamples_ReturnsExpected() { var opts = new MetricsEndpointOptions(); var stats = new OpenCensusStats(); var ep = new MetricsEndpoint(opts, stats); SetupTestView(stats, Sum.Create(), null, "test.test1"); var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1")); IAggregationData aggData = SumDataDouble.Create(100); Assert.NotNull(viewData); var result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); var sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Sum.Create(), null, "test.test2"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test2")); aggData = SumDataLong.Create(100); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Count.Create(), null, "test.test3"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test3")); aggData = CountData.Create(100); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Single(result); sample = result[0]; Assert.Equal(100, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); SetupTestView(stats, Mean.Create(), null, "test.test4"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test4")); aggData = MeanData.Create(100, 50, 1, 500); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Equal(2, result.Count); sample = result[0]; Assert.Equal(50, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); sample = result[1]; Assert.Equal(100 * 50, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); SetupTestView(stats, Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 10.0, 20.0 })), null, "test.test5"); viewData = stats.ViewManager.GetView(ViewName.Create("test.test5")); aggData = DistributionData.Create(100, 50, 5, 200, 5, new List <long>() { 10, 20, 20 }); Assert.NotNull(viewData); result = ep.GetMetricSamples(aggData, viewData); Assert.NotNull(result); Assert.Equal(3, result.Count); sample = result[0]; Assert.Equal(50, sample.Value); Assert.Equal(MetricStatistic.COUNT, sample.Statistic); sample = result[1]; Assert.Equal(200, sample.Value); Assert.Equal(MetricStatistic.MAX, sample.Statistic); sample = result[2]; Assert.Equal(100 * 50, sample.Value); Assert.Equal(MetricStatistic.TOTALTIME, sample.Statistic); }
public void TestEquals() { var a1 = SumDataDouble.Create(10.0); var a2 = SumDataDouble.Create(20.0); var a3 = SumDataLong.Create(20); var a5 = CountData.Create(40); var a6 = CountData.Create(80); var a7 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a8 = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 100L }); var a9 = DistributionData.Create(110, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a10 = DistributionData.Create(10, 110, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a11 = DistributionData.Create(10, 10, -1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a12 = DistributionData.Create(10, 10, 1, 5, 0, new List <long>() { 0L, 10L, 0L }); var a13 = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>() { 0L, 10L, 0L }); var a14 = MeanData.Create(5.0, 1, 5.0, 5.0); var a15 = MeanData.Create(-5.0, 1, -5.0, -5.0); var a16 = LastValueDataDouble.Create(20.0); var a17 = LastValueDataLong.Create(20); var a1a = SumDataDouble.Create(10.0); var a2a = SumDataDouble.Create(20.0); var a3a = SumDataLong.Create(20); var a5a = CountData.Create(40); var a6a = CountData.Create(80); var a7a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a8a = DistributionData.Create(10, 10, 1, 1, 0, new List <long>() { 0L, 10L, 100L }); var a9a = DistributionData.Create(110, 10, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a10a = DistributionData.Create(10, 110, 1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a11a = DistributionData.Create(10, 10, -1, 1, 0, new List <long>() { 0L, 10L, 0L }); var a12a = DistributionData.Create(10, 10, 1, 5, 0, new List <long>() { 0L, 10L, 0L }); var a13a = DistributionData.Create(10, 10, 1, 1, 55.5, new List <long>() { 0L, 10L, 0L }); var a14a = MeanData.Create(5.0, 1, 5.0, 5.0); var a15a = MeanData.Create(-5.0, 1, -5.0, -5.0); var a16a = LastValueDataDouble.Create(20.0); var a17a = LastValueDataLong.Create(20); Assert.Equal(a1, a1a); Assert.Equal(a2, a2a); Assert.Equal(a3, a3a); Assert.Equal(a5, a5a); Assert.Equal(a6, a6a); Assert.Equal(a7, a7a); Assert.Equal(a8, a8a); Assert.Equal(a9, a9a); Assert.Equal(a10, a10a); Assert.Equal(a11, a11a); Assert.Equal(a12, a12a); Assert.Equal(a13, a13a); Assert.Equal(a14, a14a); Assert.Equal(a15, a15a); Assert.Equal(a16, a16a); Assert.Equal(a17, a17a); }
public void TestMatchAndGet() { List <IAggregationData> aggregations = new List <IAggregationData>() { SumDataDouble.Create(10.0), SumDataLong.Create(100000000), CountData.Create(40), MeanData.Create(100.0, 10, 300.0, 500.0), DistributionData.Create(1, 1, 1, 1, 0, new List <long>() { 0L, 10L, 0L }), LastValueDataDouble.Create(20.0), LastValueDataLong.Create(200000000L), }; List <object> actual = new List <object>(); foreach (IAggregationData aggregation in aggregations) { aggregation.Match <object>( (arg) => { actual.Add(arg.Sum); return(null); }, (arg) => { actual.Add(arg.Sum); return(null); }, (arg) => { actual.Add(arg.Count); return(null); }, (arg) => { actual.Add(arg.Mean); return(null); }, (arg) => { actual.Add(arg.BucketCounts); return(null); }, (arg) => { actual.Add(arg.LastValue); return(null); }, (arg) => { actual.Add(arg.LastValue); return(null); }, (arg) => { throw new ArgumentException(); }); } Assert.Equal(10.0, actual[0]); Assert.Equal(100000000L, actual[1]); Assert.Equal(40L, actual[2]); Assert.Equal(100.0, actual[3]); Assert.Equal(new List <long>() { 0L, 10L, 0L }, actual[4]); Assert.Equal(20.0, actual[5]); Assert.Equal(200000000L, actual[6]); }
private static int CalculateLineCount(RateType type, IWordCountBatchTaskSettings settings, CountData countData, CountTotal total, ref int output, ref int totalChar) { if (!string.IsNullOrWhiteSpace(settings.CharactersPerLine)) { if (int.TryParse(settings.CharactersPerLine, out output)) { if (type == RateType.Locked && settings.ReportLockedSeperately) { if (settings.IncludeSpaces) { totalChar = countData.Characters + total.LockedSpaceCountTotal; } else { totalChar = countData.Characters; } } else { if (settings.IncludeSpaces) { if (settings.ReportLockedSeperately) { totalChar = countData.Characters + total.UnlockedSpaceCountTotal; } else { totalChar = countData.Characters + total.UnlockedSpaceCountTotal + total.LockedSpaceCountTotal; } } else { totalChar = countData.Characters; } } var num = Math.Round(Convert.ToDecimal(totalChar) / Convert.ToDecimal(output), MidpointRounding.AwayFromZero); return(Convert.ToInt32(num)); } } return(0); }
public void GenerateCreatesReport() { // Arrange var counter = Substitute.For <ISegmentWordCounter>(); counter.FileName.Returns("Some file name.sdlxliff"); var countData = CountData.Create(10, 10, 10, 10, 10); var segCountInfo1 = CreateSegmentCountInfo(countData, true); var segCountInfo2 = CreateSegmentCountInfo(countData, matchPercent: 100); var segCountInfo3 = CreateSegmentCountInfo(countData, matchPercent: 95); var segCountInfo4 = CreateSegmentCountInfo(countData, matchPercent: 85); var segCountInfo5 = CreateSegmentCountInfo(countData, matchPercent: 75); var segCountInfo6 = CreateSegmentCountInfo(countData, matchPercent: 55); var segCountInfo7 = CreateSegmentCountInfo(countData, matchPercent: 45); var languages = new Language[] { new Language("ja-JP"), new Language("en-US") }; var fileCountInfo = new FileCountInfo(new List <SegmentCountInfo>() { segCountInfo1, segCountInfo2, segCountInfo3, segCountInfo4, segCountInfo5, segCountInfo6, segCountInfo7 }, languages, Substitute.For <IRepetitionsTable>()); counter.FileCountInfo.Returns(fileCountInfo); var counters = new List <ISegmentWordCounter>() { counter }; var settings = Substitute.For <IWordCountBatchTaskSettings>(); settings.InvoiceRates = new List <InvoiceItem>() { new InvoiceItem(RateType.PerfectMatch, "1.25"), new InvoiceItem(RateType.ContextMatch, "10"), new InvoiceItem(RateType.Repetitions, "10"), new InvoiceItem(RateType.CrossFileRepetitions, "10"), new InvoiceItem(RateType.OneHundred, "1.50"), new InvoiceItem(RateType.NinetyFive, "10"), new InvoiceItem(RateType.EightyFive, "10"), new InvoiceItem(RateType.SeventyFive, "10"), new InvoiceItem(RateType.Fifty, "10"), new InvoiceItem(RateType.New, "10") }; settings.ReportLockedSeperately = false; settings.UseSource = true; settings.Culture = "English"; // Act var root = ReportGenerator.Generate(counters, settings); // Assert Assert.NotNull(root); output.WriteLine(root); }