Esempio n. 1
0
        private void SaveTileData(Tile tile, string filePath)
        {
            lock (_lockGuard)
            {
                if (CoreLibrary.HasData(tile.QuadKey))
                {
                    return;
                }

                var filePathResolved       = _pathResolver.Resolve(filePath);
                var stylesheetPathResolved = _pathResolver.Resolve(tile.Stylesheet.Path);

                Trace.Info(TraceCategory, String.Format("save tile data {0} from {1} using style: {2}",
                                                        tile, filePathResolved, stylesheetPathResolved));

                string errorMsg = null;
                CoreLibrary.AddToStore(MapStorageType.Persistent,
                                       stylesheetPathResolved,
                                       filePathResolved,
                                       tile.QuadKey,
                                       error => errorMsg = error);

                if (errorMsg != null)
                {
                    throw new MapDataException(String.Format(Strings.CannotAddDataToInMemoryStore, errorMsg));
                }
            }
        }
Esempio n. 2
0
 internal static void MaxBy()
 {
     CoreLibrary.GetExportedTypes()
     .Select(type => (Type: type, MemberCount: type.GetDeclaredMembers().Length))
     .MaxBy(typeAndMemberCount => typeAndMemberCount.MemberCount)
     .WriteLines(max => $"{max.Type.FullName}:{max.MemberCount}");     // System.Convert:311
 }
Esempio n. 3
0
        /// <summary> Downloads map data for given tile. </summary>
        private IObservable <Tile> CreateDownloadSequence(Tile tile)
        {
            // data exists in store
            if (CoreLibrary.HasData(tile.QuadKey))
            {
                return(Observable.Return(tile));
            }

            // data exists in cache
            var filePath = GetCacheFilePath(tile);

            if (_fileSystemService.Exists(filePath))
            {
                var errorMsg = SaveTileDataInMemory(tile, filePath);
                return(errorMsg == null
                    ? Observable.Return(tile)
                    : Observable.Throw <Tile>(new MapDataException(Strings.CannotAddDataToInMemoryStore, errorMsg)));
            }

            // need to download from remote server
            return(Observable.Create <Tile>(observer =>
            {
                double padding = 0.001;
                BoundingBox query = tile.BoundingBox;
                var queryString = String.Format(_mapDataServerQuery,
                                                query.MinPoint.Latitude - padding, query.MinPoint.Longitude - padding,
                                                query.MaxPoint.Latitude + padding, query.MaxPoint.Longitude + padding);
                var uri = String.Format("{0}{1}", _mapDataServerUri, Uri.EscapeDataString(queryString));
                Trace.Warn(TraceCategory, Strings.NoPresistentElementSourceFound, tile.QuadKey.ToString(), uri);
                _networkService.GetAndGetBytes(uri)
                .ObserveOn(Scheduler.ThreadPool)
                .Subscribe(bytes =>
                {
                    Trace.Debug(TraceCategory, "saving bytes: {0}", bytes.Length.ToString());
                    lock (_lockObj)
                    {
                        if (!_fileSystemService.Exists(filePath))
                        {
                            using (var stream = _fileSystemService.WriteStream(filePath))
                                stream.Write(bytes, 0, bytes.Length);
                        }
                    }

                    // try to add in memory store
                    var errorMsg = SaveTileDataInMemory(tile, filePath);
                    if (errorMsg != null)
                    {
                        observer.OnError(new MapDataException(String.Format(Strings.CannotAddDataToInMemoryStore, errorMsg)));
                    }
                    else
                    {
                        observer.OnNext(tile);
                        observer.OnCompleted();
                    }
                });

                return Disposable.Empty;
            }));
        }
Esempio n. 4
0
 /// <inheritdoc />
 public void Add(MapStorageType storageType, Element element, Range <int> levelOfDetails)
 {
     CoreLibrary.AddElementToStore(storageType,
                                   _resolver.Resolve(_stylesheet.Path),
                                   element, levelOfDetails, message =>
     {
         if (!String.IsNullOrEmpty(message))
         {
             throw new MapDataException(message);
         }
     });
 }
Esempio n. 5
0
        /// <inheritdoc />
        public IObservable <Union <Element, Mesh> > Load(Tile tile)
        {
            return(_mapDataProvider
                   .Get(tile)
                   .SelectMany(filePath =>
            {
                if (!CoreLibrary.HasData(tile.QuadKey))
                {
                    SaveTileData(tile, filePath);
                }

                return CreateLoadSequence(tile);
            }));
        }
Esempio n. 6
0
        /// <inheritdoc />
        public void Configure(IConfigSection configSection)
        {
            var stringPath  = _pathResolver.Resolve(configSection.GetString("data/index/strings"));
            var mapDataPath = _pathResolver.Resolve(configSection.GetString("data/index/spatial"));
            var elePath     = _pathResolver.Resolve(configSection.GetString("data/elevation/local"));

            string errorMsg = null;

            CoreLibrary.Configure(stringPath, mapDataPath, elePath, error => errorMsg = error);
            if (errorMsg != null)
            {
                throw new MapDataException(errorMsg);
            }
        }
Esempio n. 7
0
        private IObservable <string> CreateMapDataObservable(Tile tile)
        {
            if (CoreLibrary.HasData(tile.QuadKey))
            {
                return(Observable.Return(""));
            }

            if (OsmTileRange.Contains(tile.QuadKey.LevelOfDetail))
            {
                return(_osmMapDataProvider.Get(tile));
            }

            return(_mapzenMapDataProvider.Get(tile));
        }
Esempio n. 8
0
            /// <inheritdoc />
            public override void OnNext(Tile value)
            {
                if (CoreLibrary.HasData(value.QuadKey))
                {
                    Notify(new Tuple <Tile, string>(value, ""));
                    return;
                }

                if (OsmTileRange.Contains(value.QuadKey.LevelOfDetail))
                {
                    _osmMapDataProvider.OnNext(value);
                }
                else
                {
                    _mapzenMapDataProvider.OnNext(value);
                }
            }
Esempio n. 9
0
        public SophieVM()
        {
            MethodNames = new List<string>();
            ObjString name = Obj.MakeString("core");

            // Implicitly create a "core" module for the built in libraries.
            ObjModule coreModule = new ObjModule(name);

            _modules = new ObjMap();
            _modules.Set(Obj.Null, coreModule);

            CoreLibrary core = new CoreLibrary(this);
            core.InitializeCore();

            // Load in System functions
            Library.System.LoadSystemLibrary(this);
        }
Esempio n. 10
0
        public WrenVM()
        {
            MethodNames = new List <string>();
            ObjString name = new ObjString("core");

            // Implicitly create a "core" module for the built in libraries.
            ObjModule coreModule = new ObjModule(name);

            _modules = new ObjMap();
            _modules.Set(Obj.Null, coreModule);

            CoreLibrary core = new CoreLibrary(this);

            core.InitializeCore();

            // Load in System functions
            Meta.LoadLibrary(this);
        }
Esempio n. 11
0
        /// <inheritdoc />
        public void AddToStore(MapStorageType storageType, string dataPath, Stylesheet stylesheet, Range <int> levelOfDetails)
        {
            var dataPathResolved       = _pathResolver.Resolve(dataPath);
            var stylesheetPathResolved = _pathResolver.Resolve(stylesheet.Path);

            Trace.Info(TraceCategory, String.Format("add to {0} storage: data:{1} using style: {2}",
                                                    storageType, dataPathResolved, stylesheetPathResolved));

            string errorMsg = null;

            CoreLibrary.AddToStore(storageType, stylesheetPathResolved, dataPathResolved, levelOfDetails,
                                   error => errorMsg = error);

            if (errorMsg != null)
            {
                throw new MapDataException(errorMsg);
            }
        }
Esempio n. 12
0
        /// <summary> Adds tile data into in memory storage. </summary>
        private string SaveTileDataInMemory(Tile tile, string filePath)
        {
            var filePathResolved       = _pathResolver.Resolve(filePath);
            var stylesheetPathResolved = _pathResolver.Resolve(tile.Stylesheet.Path);

            Trace.Info(TraceCategory, String.Format("save tile data {0} from {1} using style: {2}",
                                                    tile, filePathResolved, stylesheetPathResolved));

            string errorMsg = null;

            CoreLibrary.AddToStore(MapStorageType.Persistent,
                                   stylesheetPathResolved,
                                   filePathResolved,
                                   tile.QuadKey,
                                   error => errorMsg = error);

            return(errorMsg);
        }
Esempio n. 13
0
        /// <inheritdoc />
        public void Configure(IConfigSection configSection)
        {
            _mapDataServerUri       = configSection.GetString(@"data/remote/server", null);
            _mapDataServerQuery     = configSection.GetString(@"data/remote/query", null);
            _mapDataFormatExtension = "." + configSection.GetString(@"data/remote/format", "xml");
            _cachePath = configSection.GetString(@"data/cache", null);

            var stringPath  = _pathResolver.Resolve(configSection.GetString("data/index/strings"));
            var mapDataPath = _pathResolver.Resolve(configSection.GetString("data/index/spatial"));
            var elePath     = _pathResolver.Resolve(configSection.GetString("data/elevation/local"));

            string errorMsg = null;

            CoreLibrary.Configure(stringPath, mapDataPath, elePath, error => errorMsg = error);
            if (errorMsg != null)
            {
                throw new MapDataException(errorMsg);
            }
        }
Esempio n. 14
0
        public WrenVM(Action <string> write, Action <string> error)
        {
            Write = write ?? (_ => Console.WriteLine(_));
            Error = error ?? (_ => Console.Error.WriteLine(_));

            MethodNames = new List <string>();
            ObjString name = new ObjString("core");

            // Implicitly create a "core" module for the built in libraries.
            ObjModule coreModule = new ObjModule(name);

            _modules = new ObjMap();
            _modules.Set(Obj.Null, coreModule);

            CoreLibrary core = new CoreLibrary(this);

            core.InitializeCore();

            // Load in System functions
            Meta.LoadLibrary(this);
        }
Esempio n. 15
0
        /// <summary> Creates <see cref="IObservable{T}"/> for loading element of given tile. </summary>
        private IObservable <Union <Element, Mesh> > CreateLoadSequence(Tile tile)
        {
            return(Observable.Create <Union <Element, Mesh> >(observer =>
            {
                var stylesheetPathResolved = _pathResolver.Resolve(tile.Stylesheet.Path);

                Trace.Info(TraceCategory, "loading tile: {0} using style: {1}", tile.ToString(), stylesheetPathResolved);
                var adapter = new MapTileAdapter(tile, observer, Trace);

                CoreLibrary.LoadQuadKey(
                    stylesheetPathResolved,
                    tile.QuadKey,
                    adapter.AdaptMesh,
                    adapter.AdaptElement,
                    adapter.AdaptError);

                Trace.Info(TraceCategory, "tile loaded: {0}", tile.ToString());
                observer.OnCompleted();

                return Disposable.Empty;
            }));
        }
Esempio n. 16
0
 /// <inheritdoc />
 public void Dispose()
 {
     CoreLibrary.Dispose();
 }
Esempio n. 17
0
        static void Main(string[] args)
        {
            CoreLibrary.Initialize();

            /*
             * Matrix a = new Matrix(2, 2);
             * Matrix b = new Matrix(2, 2);
             * Matrix c = new Matrix(2, 2);
             *
             * Vector v0 = new Vector(2);
             * Vector v1 = new Vector(2);
             * Vector v2 = new Vector(2);
             *
             * a[0, 0] = 1;
             * a[0, 1] = 2;
             * a[1, 0] = 4;
             * a[1, 1] = 8;
             *
             * b[0, 0] = 4;
             * b[0, 1] = 2;
             * b[1, 0] = 5;
             * b[1, 1] = 8;
             *
             * v0[0] = 1;
             * v0[1] = 2;
             *
             * v1[0] = 4;
             * v1[1] = 8;
             *
             * Matrix.Multiply(a, b, ref c);
             * Console.WriteLine("Multiply:");
             * Console.WriteLine("a=\n" + a);
             * Console.WriteLine("b=\n" + b);
             * Console.WriteLine("c=\n" + c);
             *
             * Matrix.Madd(a, v0, v1, ref v2);
             * Console.WriteLine("Madd:");
             * Console.WriteLine("a=\n" + a);
             * Console.WriteLine("v0=\n" + v0);
             * Console.WriteLine("v1=\n" + v1);
             * Console.WriteLine("v2=\n" + v2);
             *
             * Matrix.MSub(a, 10, ref c);
             * Console.WriteLine("Msub:");
             * Console.WriteLine("a=\n" + a);
             * Console.WriteLine("c=\n" + c);
             *
             *
             * Vector.MSub(v0, 10, ref v1);
             * Console.WriteLine("Msub:");
             * Console.WriteLine("v0=\n" + v0);
             * Console.WriteLine("v1=\n" + v1);
             *
             * Matrix.MultiplyToMatrix(v0, v1, ref c);
             * Console.WriteLine("VECVECMUL:");
             * Console.WriteLine("v0=\n" + v0);
             * Console.WriteLine("v1=\n" + v1);
             * Console.WriteLine("c=\n" + c);
             *
             * Matrix.TransposedMultiply(a, v0, v1, ref v2);
             * Console.WriteLine("TransposedMultiply:");
             * Console.WriteLine("a=\n" + a);
             * Console.WriteLine("v0=\n" + v0);
             * Console.WriteLine("v1=\n" + v1);
             * Console.WriteLine("v2=\n" + v2);
             *
             *
             * Console.ReadLine();
             */

            AnimeGANTest.GAN();
            Console.ReadLine();
            return;

            /*
             * NeuralNetwork net = new NeuralNetwork(new int[] { 2, 2, 1 }, new IActivationFunction[] { null, new Sigmoid(), new Sigmoid() }, new Quadratic(), new SGD());
             *
             * float[][] inputs = new float[][] { new float[] { 0, 1 }, new float[] { 1, 0 }, new float[] { 0, 0 }, new float[] { 1, 1 } };
             * float[][] outputs = new float[][] { new float[] { 1 }, new float[] { 1 }, new float[] { 0 }, new float[] { 0 } };
             *
             * for(int i = 0; i < 500000; i++)
             * {
             *  var (a , z) = net.Train(inputs[i % 4]);
             *  var (nabla_w, nabla_b) = GradientSolver.Solve(net, a, z, new Vector(outputs[i % 4]));
             *  (net.Weights, net.Biases) = net.Optimizer.Optimize(net.Weights, net.Biases, nabla_w, nabla_b, 0.05f);
             * }
             *
             * for(int i = 0; i < 4; i++)
             * {
             *  float res = net.Activate(inputs[i])[0];
             *  Console.WriteLine($"Result {i} : {res}");
             * }
             * Console.ReadLine();*/
        }
Esempio n. 18
0
 /// <summary> Loads elevation for given quadkey and point. </summary>
 public double Load(QuadKey quadKey, GeoCoordinate coordinate)
 {
     return(CoreLibrary.GetElevation(quadKey, _eleDataType, coordinate));
 }