Skip to content

Commit

Permalink
moved version 1.0.0.35 from codeplex
Browse files Browse the repository at this point in the history
  • Loading branch information
thulka committed Feb 21, 2013
1 parent baa4100 commit 76b95e7
Show file tree
Hide file tree
Showing 111 changed files with 18,534 additions and 3 deletions.
40 changes: 40 additions & 0 deletions Coverage.testsettings
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestSettings name="Coverage" id="6c9b909c-fd99-415b-ba78-15989fc03815" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>Run tests and test code coverage.</Description>
<Execution hostProcessPlatform="MSIL">
<Hosts>
<VSSDKTestHostRunConfig name="VS IDE" HiveKind="DevEnv" HiveName="10.0" xmlns="http://microsoft.com/schemas/VisualStudio/SDK/Tools/IdeHostAdapter/2006/06" />
</Hosts>
<Timeouts runTimeout="1800000" testTimeout="60000" />
<TestTypeSpecific>
<UnitTestRunConfig testTypeId="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b">
<AssemblyResolution>
<TestDirectory useLoadContext="true" />
</AssemblyResolution>
</UnitTestRunConfig>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
<Headers>
<Header name="User-Agent" value="Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)" />
<Header name="Accept" value="*/*" />
<Header name="Accept-Language" value="{{$IEAcceptLanguage}}" />
<Header name="Accept-Encoding" value="GZIP" />
</Headers>
</Browser>
</WebTestRunConfiguration>
</TestTypeSpecific>
<AgentRule name="LocalMachineDefaultRole">
<DataCollectors>
<DataCollector uri="datacollector://microsoft/CodeCoverage/1.0" assemblyQualifiedName="Microsoft.VisualStudio.TestTools.CodeCoverage.CoveragePlugIn, Microsoft.VisualStudio.QualityTools.Plugins.CodeCoverage, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" friendlyName="Code Coverage">
<Configuration>
<CodeCoverage xmlns="">
<Regular>
<CodeCoverageItem binaryFile="TeaFile\bin\Debug\DiscreteLogics.TeaFile.dll" pdbFile="TeaFile\bin\Debug\DiscreteLogics.TeaFile.pdb" instrumentInPlace="true" />
</Regular>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</AgentRule>
</Execution>
</TestSettings>
84 changes: 84 additions & 0 deletions Examples/AnalyzeTicks/AnalyzeTicks.csproj
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{35B0A885-3123-43B7-8DCA-B4CAD7B5AD41}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ACME.Examples</RootNamespace>
<AssemblyName>AnalyzeTicks</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\Bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>..\..\Bin\AnalyzeTicks.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisIgnoreBuiltInRuleSets>true</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<OutputPath>..\..\Bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisLogFile>..\..\Bin\AnalyzeTicks.exe.CodeAnalysisLog.xml</CodeAnalysisLogFile>
<CodeAnalysisUseTypeNameInSuppression>true</CodeAnalysisUseTypeNameInSuppression>
<CodeAnalysisModuleSuppressionsFile>GlobalSuppressions.cs</CodeAnalysisModuleSuppressionsFile>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRuleSetDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\\Rule Sets</CodeAnalysisRuleSetDirectories>
<CodeAnalysisRuleDirectories>;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\\Rules</CodeAnalysisRuleDirectories>
<CodeAnalysisIgnoreBuiltInRules>true</CodeAnalysisIgnoreBuiltInRules>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\TeaFiles\TeaFiles.csproj">
<Project>{1CADE377-2821-480D-A0E7-34F224886AF6}</Project>
<Name>TeaFiles</Name>
</ProjectReference>
<ProjectReference Include="..\ItemTypes\ItemTypes.csproj">
<Project>{DD952649-AD45-4B89-B87E-28F0B876171E}</Project>
<Name>ItemTypes</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
174 changes: 174 additions & 0 deletions Examples/AnalyzeTicks/Program.cs
@@ -0,0 +1,174 @@
// copyright discretelogics 2012. released under the gpl v3. see license.txt for details.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using TeaTime;

namespace ACME.Examples
{
class Program
{
class TradingSession
{
public Time Begin;
public Time End;
public int TickCount;

public TradingSession(Time time)
{
this.Begin = time.Date;
this.End = this.Begin.AddDays(1);
}

public override string ToString()
{
return this.Begin + " " + this.TickCount;
}
}

static void Main(string[] args)
{
try
{
if (args.Count() < 1) throw new Exception("Usage: AnalyzeTicks <filename> [m]emorymapped|read [n]times");
string filename = args[0];
bool memoryMapped = args.Count() >= 2
? args[1].StartsWith("m", StringComparison.InvariantCultureIgnoreCase)
: false;
int n = args.Count() >= 3 ? int.Parse(args[2]) : 1;

Console.WriteLine(Environment.Is64BitProcess ? "64bit" : "32bit");

for (int i = 1; i <= n; i++)
{
Console.WriteLine("----------------------------------");
Console.WriteLine(i + ". run");
var sw = Stopwatch.StartNew();
Run(filename, memoryMapped, n == 1);
sw.Stop();
Console.WriteLine("execution time = " + sw.Elapsed.TotalMilliseconds + "ms");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}

class Statistics
{
public double MinPrice;
public double MaxPrice;
public List<TradingSession> Sessions;

public Statistics()
{
this.Sessions = new List<TradingSession>();
}
}

static void Run(string filename, bool memoryMapped, bool displayValues)
{
using (var tf = TeaFile<Tick>.OpenRead(filename, ItemDescriptionElements.None))
{
if (tf.Items.Count == 0) throw new Exception("File holds no items.");
}

Statistics stats;
if (memoryMapped)
{
stats = GetSessionDataMemMapped(filename);
}
else
{
stats = GetSessionData(filename);
}

int minTransactions = int.MaxValue;
int maxTransactions = int.MinValue;
foreach (var session in stats.Sessions)
{
minTransactions = Math.Min(minTransactions, session.TickCount);
maxTransactions = Math.Max(maxTransactions, session.TickCount);
}
Console.WriteLine("min price = " + stats.MinPrice);
Console.WriteLine("max price = " + stats.MaxPrice);
Console.WriteLine("min ticks per session = " + minTransactions);
Console.WriteLine("max ticks per session = " + maxTransactions);

var tickCounts = stats.Sessions.Select(s => s.TickCount).ToArray();
Array.Sort(tickCounts);
int median = tickCounts[tickCounts.Length / 2];
Console.WriteLine("median = " + median);

if (displayValues)
{
double minimumExpectedTicksPerSession = median / 2.0;
Console.WriteLine("First 10 sessions:");
foreach (var s in stats.Sessions.Take(10))
{
Console.WriteLine(s + " " + ((s.TickCount >= minimumExpectedTicksPerSession) ? "OK" : "QUESTIONABLE"));
}
}
}

static Statistics GetSessionDataMemMapped(string filename)
{
using (var mf = RawMemoryMapping<Tick>.OpenRead(filename))
unsafe
{
var stats = new Statistics();
Tick* firstTick = (Tick*)mf.ItemAreaStart;
double minPrice = firstTick->Price;
double maxPrice = firstTick->Price;
var session = new TradingSession(firstTick->Time);
stats.Sessions.Add(session);
for (var t = firstTick; t != mf.ItemAreaEnd; t++)
{
if (t->Time >= session.End)
{
session = new TradingSession(t->Time);
stats.Sessions.Add(session);
}
session.TickCount++;
minPrice = Math.Min(t->Price, minPrice);
maxPrice = Math.Max(t->Price, maxPrice);
}
stats.MinPrice = minPrice;
stats.MaxPrice = maxPrice;
return stats;
}
}

static Statistics GetSessionData(string filename)
{
using (var tf = TeaFile<Tick>.OpenRead(filename, ItemDescriptionElements.None))
{
var stats = new Statistics();
Tick firstTick = tf.Items.First();
double minPrice = firstTick.Price;
double maxPrice = firstTick.Price;
var session = new TradingSession(firstTick.Time);
stats.Sessions.Add(session);
int n = 0;
foreach (var tick in tf.Items)
{
if (tick.Time >= session.End)
{
session = new TradingSession(tick.Time);
stats.Sessions.Add(session);
}
session.TickCount++;

minPrice = Math.Min(tick.Price, minPrice);
maxPrice = Math.Max(tick.Price, maxPrice);
n++;
}
stats.MinPrice = minPrice;
stats.MaxPrice = maxPrice;
return stats;
}
}
}
}

0 comments on commit 76b95e7

Please sign in to comment.