public static void TestWriteArctic(string lib = "net.securities", string host = "localhost", bool purge = true, bool del = true, string symbol = "S1") { var driver = new MongoClient("mongodb://" + host); var arctic = new Arctic(driver, lib, purge: purge); if (del) { var delcnt = arctic.DeleteAsync(symbol).Result; Console.WriteLine("Deleted {0} versi\tons for {1}".Args(delcnt, symbol)); } //var df = SampleDataFrame (); var df = RandomDataFrame(); //var df2 = SampleDataFrame (df[0].AsDateTime()[-1]); Stopwatch sw = new Stopwatch(); sw.Start(); var version = arctic.AppendAsync(symbol, df, CHUNKSIZE).Result; //var version2 = arctic.AppendAsync (symbol, df2, CHUNKSIZE).Result; sw.Stop(); long rows = df.Rows.Count;// + df2.Rows.Count; Console.WriteLine("write {0} took {1}s = {2}/sec -> ver:\n {3}".Args(rows, sw.Elapsed.TotalSeconds, rows / sw.Elapsed.TotalSeconds, version)); }
static void Main(string[] args) { Arctic arcticHabitat = new Arctic(); Rainforest rainforestHabitat = new Rainforest(); arcticHabitat.inhabitants = new List <Animal>(); Penguin larry = new Penguin(); larry.species = new EudyptesChrysolophus(); larry.name = "Larry"; Penguin betty = new Penguin(); betty.species = new EudyptesChrysolophus(); betty.name = "Betty"; arcticHabitat.inhabitants.Add(larry); arcticHabitat.inhabitants.Add(betty); foreach (Animal a in arcticHabitat.inhabitants) { Console.WriteLine(a.name); Console.WriteLine("{0} the {1} in the genus {2}. To find out more visit {3}.", a.name, a.species.commonName, a.species.genus.scientificName, a.species.url); } Console.ReadLine(); }
public static void TestArcticDateTimeIndex(string lib = "net.securities", string host = "localhost", bool purge = true, bool del = true, string symbol = "S1") { var driver = new MongoClient("mongodb://" + host); var arctic = new Arctic(driver, lib, purge: purge); if (del) { var delcnt = arctic.DeleteAsync(symbol).Result; Console.WriteLine("Deleted {0} versi\tons for {1}".Args(delcnt, symbol)); } var df = new DataFrame(new Series[] { new DateTimeSeries(new[] { new DateTime(2014, 1, 1), new DateTime(2014, 2, 1) }, name: "date"), new Series <long>(new long[] { 1, 2 }, name: "val") }, index: "date"); var df2 = new DataFrame(new Series[] { new DateTimeSeries(new[] { new DateTime(2014, 3, 1), new DateTime(2014, 4, 1) }, name: "date"), new Series <long>(new long[] { 3, 4 }, name: "val") }, index: "date"); var df4 = new DataFrame(new Series[] { new DateTimeSeries(new[] { new DateTime(2014, 3, 1), new DateTime(2014, 4, 1), new DateTime(2014, 5, 1) }, name: "date"), new Series <long>(new long[] { 3, 4, 5 }, name: "val") }, index: "date"); var df3 = new DataFrame(new Series[] { new DateTimeSeries(new[] { new DateTime(2014, 5, 1), new DateTime(2014, 6, 1) }, name: "date"), new Series <long>(new long[] { 5, 6 }, name: "val") }, index: "date"); Stopwatch sw = new Stopwatch(); sw.Start(); var version = arctic.AppendAsync(symbol, df, CHUNKSIZE).Result; var version2 = arctic.AppendAsync(symbol, df2, CHUNKSIZE).Result; var version3 = arctic.AppendAsync(symbol, df2, CHUNKSIZE).Result; var version4 = arctic.AppendAsync(symbol, df4, CHUNKSIZE).Result; var read1 = arctic.Read(symbol, new DateRange(new DateTime(2014, 3, 1))); Console.WriteLine(read1); var read2 = arctic.Read(symbol, new DateRange(new DateTime(2014, 1, 1), new DateTime(2014, 2, 1))); Console.WriteLine(read2); sw.Stop(); long rows = df.Rows.Count;// + df2.Rows.Count; Console.WriteLine("write {0} took {1}s = {2}/sec -> ver:\n {3}".Args(rows, sw.Elapsed.TotalSeconds, rows / sw.Elapsed.TotalSeconds, version)); }
public static void TestReadArctic(string lib = "bench.securities", string host = "localhost", string symbol = "S1") { var driver = new MongoClient("mongodb://" + host); var arctic = new Arctic(driver, lib); Stopwatch sw = new Stopwatch(); sw.Start(); var df = arctic.ReadAsync(symbol).Result; sw.Stop(); if (df != null) { Console.WriteLine(df); Console.WriteLine("read {0} took {1}s = {2}/sec".Args(df.Rows.Count, sw.Elapsed.TotalSeconds, df.Rows.Count / sw.Elapsed.TotalSeconds)); } else { Console.WriteLine("Not found {0}".Args(symbol)); } }
private void CreatePoles() { Log("Map: Creating poles"); for (int x = 0; x < WIDTH; x++) { foreach (int y in new int[] { 0, (HEIGHT - 1) }) { _tiles[x, y] = new Arctic(x, y, false); } } for (int i = 0; i < (WIDTH / 4); i++) { foreach (int y in new int[] { 0, 1, (HEIGHT - 2), (HEIGHT - 1) }) { int x = Common.Random.Next(WIDTH); _tiles[x, y] = new Tundra(x, y, false); } } }
private void LoadMap(Bytemap bitmap) { _tiles = new ITile[WIDTH, HEIGHT]; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { ITile tile; bool special = TileIsSpecial(x, y); switch (bitmap[x, y]) { case 2: tile = new Forest(x, y, special); break; case 3: tile = new Swamp(x, y, special); break; case 6: tile = new Plains(x, y, special); break; case 7: tile = new Tundra(x, y, special); break; case 9: tile = new River(x, y); break; case 10: tile = new Grassland(x, y); break; case 11: tile = new Jungle(x, y, special); break; case 12: tile = new Hills(x, y, special); break; case 13: tile = new Mountains(x, y, special); break; case 14: tile = new Desert(x, y, special); break; case 15: tile = new Arctic(x, y, special); break; default: tile = new Ocean(x, y, special); break; } _tiles[x, y] = tile; } } }
public void ChangeTileType(int x, int y, Terrain type) { bool special = TileIsSpecial(x, y); bool road = _tiles[x, y].Road; bool railRoad = _tiles[x, y].RailRoad; switch (type) { case Terrain.Forest: _tiles[x, y] = new Forest(x, y, special); break; case Terrain.Swamp: _tiles[x, y] = new Swamp(x, y, special); break; case Terrain.Plains: _tiles[x, y] = new Plains(x, y, special); break; case Terrain.Tundra: _tiles[x, y] = new Tundra(x, y, special); break; case Terrain.River: _tiles[x, y] = new River(x, y); break; case Terrain.Grassland1: case Terrain.Grassland2: _tiles[x, y] = new Grassland(x, y); break; case Terrain.Jungle: _tiles[x, y] = new Jungle(x, y, special); break; case Terrain.Hills: _tiles[x, y] = new Hills(x, y, special); break; case Terrain.Mountains: _tiles[x, y] = new Mountains(x, y, special); break; case Terrain.Desert: _tiles[x, y] = new Desert(x, y, special); break; case Terrain.Arctic: _tiles[x, y] = new Arctic(x, y, special); break; case Terrain.Ocean: _tiles[x, y] = new Ocean(x, y, special); break; } _tiles[x, y].Road = road; _tiles[x, y].RailRoad = railRoad; }
private void MergeElevationAndLatitude(int[,] elevation, int[,] latitude) { Log("Map: Stage 3 - Merge elevation and latitude into the map"); // merge elevation and latitude into the map for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { bool special = TileIsSpecial(x, y); switch (elevation[x, y]) { case 0: _tiles[x, y] = new Ocean(x, y, special); break; case 1: { switch (latitude[x, y]) { case 0: _tiles[x, y] = new Desert(x, y, special); break; case 1: _tiles[x, y] = new Plains(x, y, special); break; case 2: _tiles[x, y] = new Tundra(x, y, special); break; case 3: _tiles[x, y] = new Arctic(x, y, special); break; } } break; case 2: _tiles[x, y] = new Hills(x, y, special); break; default: _tiles[x, y] = new Mountains(x, y, special); break; } } } }
public static void TestMetadata(string lib = "net.securities", string host = "localhost", bool purge = true, bool del = true, string symbol = "S1") { var driver = new MongoClient("mongodb://" + host); var arctic = new Arctic(driver, lib, purge: purge); if (del) { var delcnt = arctic.DeleteAsync(symbol).Result; Console.WriteLine("Deleted {0} versi\tons for {1}".Args(delcnt, symbol)); } var df = new DataFrame(); df.FilledCount = 2; df.Col <DateTime>("date")[0] = new DateTime(2015, 1, 1); df.Col <DateTime>("date")[1] = new DateTime(2015, 2, 1); df.Col <long>("value")[0] = 15; df.Metadata["sector"] = "internet"; df.Index = df["date"]; arctic.Append("AAPL", df); var df1 = arctic.Read("AAPL"); Console.WriteLine($"AAPL metadata {df1.Metadata["sector"]}"); }
private void ClimateAdjustments() { Log("Map: Stage 4 - Climate adjustments"); int wetness, latitude; for (int y = 0; y < HEIGHT; y++) { int yy = (int)(((float)y / HEIGHT) * 50); wetness = 0; latitude = Math.Abs(25 - yy); for (int x = 0; x < WIDTH; x++) { if (_tiles[x, y].Type == Terrain.Ocean) { // wetness yield int wy = latitude - 12; if (wy < 0) { wy = -wy; } wy += (_climate * 4); if (wy > wetness) { wetness++; } } else if (wetness > 0) { bool special = TileIsSpecial(x, y); int rainfall = Common.Random.Next(7 - (_climate * 2)); wetness -= rainfall; switch (_tiles[x, y].Type) { case Terrain.Plains: _tiles[x, y] = new Grassland(x, y); break; case Terrain.Tundra: _tiles[x, y] = new Arctic(x, y, special); break; case Terrain.Hills: _tiles[x, y] = new Forest(x, y, special); break; case Terrain.Desert: _tiles[x, y] = new Plains(x, y, special); break; case Terrain.Mountains: wetness -= 3; break; } } } wetness = 0; latitude = Math.Abs(25 - yy); // reset row wetness to 0 for (int x = WIDTH - 1; x >= 0; x--) { if (_tiles[x, y].Type == Terrain.Ocean) { // wetness yield int wy = (latitude / 2) + _climate; if (wy > wetness) { wetness++; } } else if (wetness > 0) { bool special = TileIsSpecial(x, y); int rainfall = Common.Random.Next(7 - (_climate * 2)); wetness -= rainfall; switch (_tiles[x, y].Type) { case Terrain.Swamp: _tiles[x, y] = new Forest(x, y, special); break; case Terrain.Plains: new Grassland(x, y); break; case Terrain.Grassland1: case Terrain.Grassland2: _tiles[x, y] = new Jungle(x, y, special); break; case Terrain.Hills: _tiles[x, y] = new Forest(x, y, special); break; case Terrain.Mountains: _tiles[x, y] = new Forest(x, y, special); wetness -= 3; break; case Terrain.Desert: _tiles[x, y] = new Plains(x, y, special); break; } } } } }