Ejemplo n.º 1
0
        public SVDRecommender(DataModel dataModel, Factorizer factorizer, CandidateItemsStrategy candidateItemsStrategy, PersistenceStrategy persistenceStrategy)
            : base(dataModel, candidateItemsStrategy)
        {
            Action refreshRunnable = null;

            this.factorizer          = factorizer;
            this.persistenceStrategy = persistenceStrategy;
            try
            {
                this.factorization = persistenceStrategy.load();
            }
            catch (IOException exception)
            {
                throw new TasteException("Error loading factorization", exception);
            }
            if (this.factorization == null)
            {
                this.train();
            }
            if (refreshRunnable == null)
            {
                refreshRunnable = () => this.train();
            }
            this.refreshHelper = new RefreshHelper(refreshRunnable);
            this.refreshHelper.addDependency(this.getDataModel());
            this.refreshHelper.addDependency(factorizer);
            this.refreshHelper.addDependency(candidateItemsStrategy);
        }
Ejemplo n.º 2
0
        public static void Run(PersistenceStrategy strategy, IDependencyInjector container)
        {
            container.BindToConstant <ILogger>(new DefaultLogger());

            container.Get <ILogger>().Trace("Bootstrapper", "starting the bootstrapper.");

            SetupBus(container);
            SetupDomainCommandHandlers(container);

            switch (strategy)
            {
            case PersistenceStrategy.InMemory:
                container.Get <ILogger>().Trace("Bootstrapper", "bootstrapping In-Memory strategy");
                SetupInMemoryRepo(container);
                break;

            case PersistenceStrategy.InMemoryEventSourcing:
                container.Get <ILogger>().Trace("Bootstrapper", "bootstrapping In-Memory ES strategy");
                SetupInMemoryEsRepo(container);
                break;

            default:
                container.Get <ILogger>().Trace("Bootstrapper", "bootstrapping RavenDb strategy");
                SetupRavenDbRepo(container);
                break;
            }

            container.Get <ILogger>().Trace("Bootstrapper", "done.");
        }
Ejemplo n.º 3
0
        public async Task <bool> TrySetStringAsync(string key, string value)
        {
            try
            {
                await PersistenceStrategy.SaveAsync(key, value);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> TrySetAsync <T>(string key, T value)
        {
            try
            {
                var result = SerializationStrategy.Serialize(value);
                await PersistenceStrategy.SaveAsync(key, result);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Ejemplo n.º 5
0
        private void CreateDataPoint(Reading newReading, PersistenceStrategy persistStrategy)
        {
            DateTime originalSlotExpiryTimestamp = this.slotExpiryTimestamp;

            // Push as many missing NaN data points as necessary to the queue
            PushMissingDataPoints(newReading.Timestamp);

            /*
             * Calculate the percentage of readings that are missing versus the x
             * factor (minimum % of readings required for the current slot
             * to produce a valid value.) If the percentage is the same or higher
             * than the x factor then push the accumulated data point into the queue. If
             * sufficient readings have not accumulated during this slot, then push a
             * NaN data point into the queue.
             */
            if (CalcAccumulatedReadingsRatioAsPercentage() >= this.template.XFactor)
            {
                /*
                 * Sufficient readings have been received so push the consolidated data point. The
                 * data point inherits the timestamp of the final reading
                 */
                this.dataPointCircularQueue.Add(CreateConsolidationFunction().CreateAccumulatedDataPoint(newReading));
            }
            else
            {
                /*
                 * Not enough readings have been received for the current
                 * slot, push a NaN value into the queue
                 */
                this.dataPointCircularQueue.Add(DataPoint.CreateNaN(newReading.Timestamp));
            }

            ResetAccumulatedReadings();

            if (originalSlotExpiryTimestamp == this.slotExpiryTimestamp)
            {
                CalcNextSlotExpiryTime();
            }

            if (persistStrategy != PersistenceStrategy.DelayWrite)
            {
                // Save the changes that haven't been persisted to disk
                this.dataPointCircularQueue.PersistChanges();
            }
        }
Ejemplo n.º 6
0
        public static async Task <int> Execute(
            IBlockchainStoreRepositoryFactory repositoryFactory,
            BlockchainSourceConfiguration configuration,
            FilterContainer filterContainer = null,
            bool useGeth = false)
        {
            IWeb3Wrapper web3 = new Web3Wrapper(
                useGeth
                    ? new Web3Geth(configuration.BlockchainUrl)
                    : new Web3.Web3(configuration.BlockchainUrl));

            using (_strategy = new PersistenceStrategy(
                       repositoryFactory, filterContainer, minimumBlockNumber: configuration.MinimumBlockNumber ?? 0))
            {
                var blockProcessor = new BlockProcessorFactory()
                                     .Create(
                    web3,
                    _strategy,
                    configuration.PostVm,
                    configuration.ProcessBlockTransactionsInParallel);

                var blockchainProcessor = new BlockchainProcessor(_strategy, blockProcessor);

                //this should not really be necessary
                //but without it, when the process is killed early, some csv records where not being flushed
                AppDomain.CurrentDomain.ProcessExit += (s, e) =>
                {
                    _strategy?.Dispose();
                };

                var stopWatch = Stopwatch.StartNew();

                var result = await blockchainProcessor.ExecuteAsync(configuration.FromBlock, configuration.ToBlock)
                             .ConfigureAwait(false);

                System.Console.WriteLine("Duration: " + stopWatch.Elapsed);

                Debug.WriteLine($"Finished With Success: {result}");
                System.Console.WriteLine("Finished. Success:" + result);
                System.Console.ReadLine();

                return(result ? 0 : 1);
            }
        }
Ejemplo n.º 7
0
        public async Task <TryResult <string> > TryGetStringAsync(string key)
        {
            var keys = await PersistenceStrategy.GetKeysAsync();

            if (!(keys).Contains(key))
            {
                return(new TryResult <string>());
            }
            try
            {
                var value = await PersistenceStrategy.LoadAsync(key) as string;

                return(new TryResult <string> {
                    Success = true, Value = value
                });
            }
            catch
            {
                return(new TryResult <string>());
            }
        }
Ejemplo n.º 8
0
        public async Task <TryResult <T> > TryGetAsync <T>(string key)
        {
            var keys = await PersistenceStrategy.GetKeysAsync();

            if (!(keys).Contains(key))
            {
                return(new TryResult <T>());
            }
            try
            {
                var result = await PersistenceStrategy.LoadAsync(key);

                var value = SerializationStrategy.Deserialize <T>(result);
                return(new TryResult <T> {
                    Success = true, Value = value
                });
            }
            catch
            {
                return(new TryResult <T>());
            }
        }
Ejemplo n.º 9
0
 public Program(PersistenceStrategy strategy)
 {
     _strategy  = strategy;
     _container = new SimpleDependencyInjector();
     Boostrapper.Run(strategy, _container);
 }
Ejemplo n.º 10
0
 public async Task ClearAsync() => await PersistenceStrategy.ClearAsync();
Ejemplo n.º 11
0
 public async Task <string[]> GetKeysAsync() => await PersistenceStrategy.GetKeysAsync();
 public static void AddStrategy(string key, PersistenceStrategy strategy)
 {
     strategies[key] = strategy;
 }
Ejemplo n.º 13
0
 public SVDRecommender(DataModel dataModel, Factorizer factorizer, PersistenceStrategy persistenceStrategy)
     : this(dataModel, factorizer, AbstractRecommender.getDefaultCandidateItemsStrategy(), persistenceStrategy)
 {
 }