Example #1
0
        public static DateTime LastDate(string code)
        {
            PipelineDefinition <BsonDocument, BsonDocument> pipeline = new BsonDocument[] {
                new BsonDocument("$match", new BsonDocument("Kod", code)),
                new BsonDocument()
                {
                    { "$group",
                      new BsonDocument()
                      {
                          { "_id", new BsonDocument() },
                          { "maxDate", new BsonDocument("$max", "$Tarih") },
                      } }
                },
                new BsonDocument("$project", new BsonDocument("_id", 0))
            };

            try
            {
                var date = MongoDBService.GetService().GetCollection().Aggregate(pipeline).ToList().ElementAt(0);
                return(date.GetElement("maxDate").Value.ToLocalTime());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task <IActionResult> GetTopThousand()
        {
            var service = new MongoDBService("mongodb://localhost:27017", "NetCoreTest", "ImportCSV");
            var result  = await service.GetTopThousand();

            return(Ok(result));
        }
Example #3
0
        public async Task <JsonResult> Get()
        {
            var mongoDBService = new MongoDBService("Usuarios", "profesores", "mongodb://localhost:27017", "p");
            var allProfes      = await mongoDBService.GetAllProfes();

            return(Json(allProfes));
        }
        public static List <BsonDocument> GetData(string code, DateTime targetDate, int limit)
        {
            BsonDocument filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", targetDate) }
            };

            return(MongoDBService.GetService().FindManySortLimit(filter, sort, limit));
        }
Example #5
0
        public App(string databaseLocation)
        {
            InitializeComponent();

            MainPage         = new NavigationPage(new MainPage());
            DatabaseLocation = databaseLocation;
            _mongoDBService  = new MongoDBService("TravelRecordDB");
        }
Example #6
0
        public IActionResult Index()
        {
            MongoDBService mongoDBService = new MongoDBService();
            var            result         = mongoDBService.Get();

            ViewBag.result = result.ToJson();
            return(View());
        }
Example #7
0
        public MainPage()
        {
            InitializeComponent();
            var assembly = typeof(MainPage);

            viewModel      = new MainVM();
            BindingContext = viewModel
                             iconImage.Source = ImageSource.FromResource("TravelRecordApp.Assets.Images.plane.png", assembly);
            _mongoDBService = new MongoDBService("TravelRecordDB");
        }
        public static List <BsonDocument> GetData(string code, DateTime targetDate, string projectionField, int limit)
        {
            BsonDocument filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", targetDate) }
            };
            BsonDocument projection = new BsonDocument {
                { "_id", 0 }, { projectionField, 1 }
            };

            return(MongoDBService.GetService().FindManySortProjectLimit(filter, sort, projection, limit));
        }
Example #9
0
        public TestMongoDBCore()
        {
            var builder = new ConfigurationBuilder()
                          .AddConfigurationFile("MongoDB.json", optional: true, reloadOnChange: true);
            var cb = new ContainerBuilder();

            cb.AddMongoDB();
            var con = cb.Build();

            mongoDBService = con.Resolve <MongoDBService>();
        }
        public static List <BsonDocument> GetData(string code, DateTime targetDate, string[] projectionFields)
        {
            BsonDocument filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", targetDate) }
            };
            BsonDocument projection = new BsonDocument("_id", 0);

            foreach (string field in projectionFields)
            {
                projection.Add(new BsonElement(field, 1));
            }
            return(MongoDBService.GetService().FindManySortProject(filter, sort, projection));
        }
        public JsonResult adPlaylogSave(T_AD_PLAY_LOG_MONGO param, string AD_CODES, string AD_TITLES)
        {
            //logger.Debug("adPlaylogSave after =>" + base.GetParameter());


            //RTN_SAVE_DATA data = new AdvertisingService().AdPlayLogSave(param);
            RTN_SAVE_DATA data = new MongoDBService().AdPlayLogSave(param, AD_CODES, AD_TITLES);

            //logger.Debug("adPlaylogSave after =>" + base.GetParameter());
            return(new JsonResult {
                Data = data
            });
        }
        public JsonResult AdPlayScheduler()
        {
            var rtn = new MongoDBService().MongoDBToSqlServer(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd"));

            if (string.IsNullOrEmpty(rtn.ERROR_MESSAGE))
            {
                SessionHelper.ScheduleInfo = new MongoDBService().GetAdPlayShedulerInfo();
                rtn.DATA  = SessionHelper.ScheduleInfo.MONGODB_BASE_DATE.ToFormatDate();
                rtn.DATA2 = SessionHelper.ScheduleInfo.MONGODB_APPLY_TIME.ToString();
            }
            return(new JsonResult {
                Data = rtn
            });
        }
Example #13
0
        public virtual void ProcessRequest(HttpContext context)
        {
            var dbProxy    = new MongoDBService();
            var encryption = new EncryptionService();

            _httpProxy      = new HttpContextProxy(context);
            _initData       = _httpProxy;
            _logger         = Logger.GetLogger(this.GetType().Name, _httpProxy.TransactionId, dbProxy);
            _actionExecuter = new ActionExecuter(_logger);
            CreateRoute();
            _httpContext    = context;
            _contentHandler = new WwwrootContentHandler(_httpProxy, dbProxy, _viewEngine, _actionExecuter, _logger);
            HandleAuthTokenKey(dbProxy, encryption);
            HandleSession(context);
        }
Example #14
0
        private void CreateInstallInstance()
        {
            var dbProxy            = new MongoDBService();
            var appInstallerLogger = Logger.GetLogger(typeof(ModuleInstaller.Installer.ModuleInstaller).Name, _httpProxy.TransactionId, dbProxy);
            var pingService        = new PingService(new MongoDBService());
            var routings           = ZNxtApp.Core.Web.Routings.Routings.GetRoutings();

            _appInstaller = ZNxtApp.Core.AppInstaller.Installer.GetInstance(
                pingService,
                new Helpers.DataBuilderHelper(),
                appInstallerLogger,
                dbProxy,
                new EncryptionService(),
                new ModuleInstaller.Installer.ModuleInstaller(appInstallerLogger, dbProxy),
                routings);
        }
Example #15
0
        public void Insert()
        {
            var document = new BsonDocument
            {
                { "item", "canvas" },
                { "qty", 100 },
                { "tags", new BsonArray {
                      "cotton"
                  } },
                { "size", new BsonDocument {
                      { "h", 28 }, { "w", 35.5 }, { "uom", "cm" }
                  } }
            };

            MongoDBService mongoDBService = new MongoDBService();

            mongoDBService.InsertDocument(document);
        }
Example #16
0
        private void codeSelectionNext_Click(object sender, EventArgs e)
        {
            Code = codeSelectionComboBox.SelectedItem.ToString();

            dateSelectionTitle.Text = Code + " için hangi tarih en son gün olarak seçilsin?";

            var filter     = new BsonDocument("Kod", Code);
            var sort       = new BsonDocument("Tarih", -1);
            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };

            var endDate = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();

            monthCalendar.SetDate(endDate);

            dateSelectionPanel.BringToFront();
        }
Example #17
0
        static void Main(string[] args)
        {
            RTN_SAVE_DATA rtn;

            if (Convert.ToInt32(DateTime.Now.ToString("yyyyMMdd")) <= 20190516)
            {
                rtn = new MongoDBService().MongoDBToSqlServer(DateTime.Now.AddDays(-3).ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd"));
            }
            else
            {
                rtn = new MongoDBService().MongoDBToSqlServer(DateTime.Now.AddDays(-1).ToString("yyyyMMdd"), DateTime.Now.ToString("yyyyMMdd"));
            }


            //rtn = new MongoDBService().MongoDBToSqlServer(DateTime.Now.ToString("yyyyMMdd"));
            if (!string.IsNullOrEmpty(rtn.ERROR_MESSAGE))
            {
                Console.Write(rtn.ERROR_MESSAGE);
            }
        }
Example #18
0
        public static List <BsonDocument> GetCodeList()
        {
            var collection = MongoDBService.GetService().GetCollection();

            PipelineDefinition <BsonDocument, BsonDocument> pipeline = new BsonDocument[]
            {
                new BsonDocument("$group", new BsonDocument("_id", "$Kod"))
            };

            List <BsonDocument> codeList = null;

            try
            {
                codeList = collection.Aggregate(pipeline).ToList();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            return(codeList);
        }
Example #19
0
        private void buttonForCodeSelectionNext_Click(object sender, EventArgs e)
        {
            code = comboBoxForCodeSelection.SelectedItem.ToString();
            labelForDateSelectionText.Text = code + " verileri üzerinde hangi tarihten itibaren geriye doğru kaç günlük veri üzerinde çalışılacağını seçiniz.";

            PipelineDefinition <BsonDocument, BsonDocument> pipeline = new BsonDocument[] {
                new BsonDocument("$match", new BsonDocument("Kod", code)),
                new BsonDocument()
                {
                    { "$group",
                      new BsonDocument()
                      {
                          { "_id", new BsonDocument() },
                          { "minDate", new BsonDocument("$min", "$Tarih") },
                          { "maxDate", new BsonDocument("$max", "$Tarih") },
                          { "count", new BsonDocument("$sum", 1) }
                      } }
                },
                new BsonDocument("$project", new BsonDocument("_id", 0))
            };

            try
            {
                var dates = MongoDBService.GetService().GetCollection().Aggregate(pipeline).ToList().ElementAt(0);
                dateTimePickerForDateSelection.MinDate = dates.GetElement("minDate").Value.ToLocalTime();
                dateTimePickerForDateSelection.MaxDate = dates.GetElement("maxDate").Value.ToLocalTime();
                dateTimePickerForDateSelection.Value   = dates.GetElement("maxDate").Value.ToLocalTime();

                numericUpDownForNumberOfData.Maximum = dates.GetElement("count").Value.ToInt32();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            panelForDateSelection.BringToFront();
        }
        public static double[] RsiMR(string code, DateTime targetDate, int period = 14, int numberOfData = 1)
        {
            if (period <= 0)
            {
                throw new IndicatorException("Periyot pozitif sayı olmalıdır.");
            }
            else if (numberOfData <= 0)
            {
                throw new IndicatorException("Gösterilecek veri sayısı pozitif sayı olmalıdır.");
            }

            int dataCount = IndicatorService.DataCount(code, targetDate);

            if (dataCount < period)
            {
                throw new IndicatorException(IndicatorException.DATA_NOT_ENOUGH_MESSAGE);
            }

            if (dataCount < numberOfData + period - 1)
            {
                numberOfData = dataCount - period + 1;
            }

            int limit = numberOfData + period - 1;

            var filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
            };
            var sort = new BsonDocument("Tarih", -1);

            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };
            var startingDate = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, numberOfData - 1).GetElement(0).Value.ToLocalTime();
            var lastDate     = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();
            var limitDate    = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, limit - 1).GetElement(0).Value.ToLocalTime();
            var dates        = IndicatorService.GetData(code, targetDate, "Tarih", limit).Select(p => p.GetElement(0).Value.ToLocalTime()).ToArray();

            MapReduceOptions <BsonDocument, BsonDocument> options = new MapReduceOptions <BsonDocument, BsonDocument>
            {
                Filter = new BsonDocument {
                    { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
                },
                Sort  = new BsonDocument("Tarih", -1),
                Scope = new BsonDocument {
                    { "startingDate", startingDate }, { "lastDate", lastDate }, { "limitDate", limitDate }, { "period", period }, { "numberOfData", numberOfData }, { "binarySearch", MapReduceHelpers.BinarySearch }, { "equalityFunction", MapReduceHelpers.IsDatesEqual }, { "dates", new BsonArray(dates) }
                },
                OutputOptions = MapReduceOutputOptions.Replace("rsiOut", "financialData", false)
            };

            double[]       avg;
            BsonJavaScript mapper = new BsonJavaScript(@"
                function() {
                    if (!equalityFunction(this.Tarih, limitDate) && this.Tarih < limitDate)
                        return;
                    else if (!equalityFunction(this.Tarih, lastDate) && this.Tarih > lastDate)
                        return;

                    var dateIndex;

                    dateIndex = binarySearch(dates, this.Tarih);
                    if (dateIndex == -1)
                        return;

                    for (var i = 0; i < period && dateIndex >= 0; i++, dateIndex--) {
                        if (dates[dateIndex] > startingDate || equalityFunction(dates[dateIndex], startingDate))
                            emit(dates[dateIndex], {date: this.Tarih, headClose : this.Kapanis, tailClose : this.Kapanis, gain: 0 , loss: 0});
                    }
                }
            ");

            BsonJavaScript reducer = new BsonJavaScript(@"
                function(key, values) {
	                values.sort(function(a, b) {
		                return a.date < b.date;
	                });

                    sumGain = values[0].gain; 
                    sumLoss = values[0].loss;
                    var diff;
    
                    for(var i = 0; i < values.length - 1; i++) {
                        sumGain += values[i+1].gain;   
                        sumLoss += values[i+1].loss;
                        diff = values[i].tailClose - values[i+1].headClose;
                        if(diff > 0) 
                            sumGain += diff;
                        else 
                            sumLoss -= diff;
                    }

                    return {date: values[0].date, headClose: values[0].headClose, tailClose: values[values.length-1].tailClose, gain: sumGain, loss: sumLoss};
                }
            ");

            BsonJavaScript finalizer = new BsonJavaScript(@"
                function(key, reducedValue) {
                    if (reducedValue.loss == 0) return 100;
                    reducedValue = 100 - 100 / (1 + (reducedValue.gain / reducedValue.loss));
                    return reducedValue;
                }
            ");

            options.Finalize = finalizer;

            List <BsonDocument> resultSet = MongoDBService.GetService().MapReduceMany(mapper, reducer, options);

            avg = new double[numberOfData];

            for (int i = 0, j = numberOfData - 1; i < numberOfData; i++, j--)
            {
                avg[i] = resultSet.ElementAt(j).GetElement(1).Value.ToDouble();
            }

            return(avg);
        }
Example #21
0
        public async Task Post([FromBody] ProfesorModel profe)
        {
            var mongoDBService = new MongoDBService("Usuarios", "profesores", "mongodb://localhost:27017", "p");

            await mongoDBService.InsertProfe(profe);
        }
 public void insertData(MongoDBService.Transaction tr)
 {
     tr.Name = tr.Name;
     tr.quantity = tr.quantity;
     tr.cost = tr.cost;
     tr.storeID = tr.storeID;
     Service1Client client = new Service1Client();
     client.InsertDataCompleted += new EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(proxy_InsertDataCompleted);
     client.InsertDataAsync(tr, App.UserID);
 }
Example #23
0
        public void InsertMany()
        {
            var documents = new BsonDocument[]
            {
                new BsonDocument
                {
                    { "item", "journal" },
                    { "qty", 25 },
                    { "tags", new BsonArray {
                          "blank", "red"
                      } },
                    { "size", new BsonDocument {
                          { "h", 14 }, { "w", 21 }, { "uom", "cm" }
                      } }
                },
                new BsonDocument
                {
                    { "item", "mat" },
                    { "qty", 85 },
                    { "tags", new BsonArray {
                          "gray"
                      } },
                    { "size", new BsonDocument {
                          { "h", 27.9 }, { "w", 35.5 }, { "uom", "cm" }
                      } }
                },
                new BsonDocument
                {
                    { "item", "mousepad" },
                    { "qty", 25 },
                    { "tags", new BsonArray {
                          "gel", "blue"
                      } },
                    { "size", new BsonDocument {
                          { "h", 19 }, { "w", 22.85 }, { "uom", "cm" }
                      } }
                },
                new BsonDocument
                {
                    { "item", "journal" },
                    { "qty", 25 },
                    { "tags", new BsonArray {
                          "blank", "red"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "notebook" },
                    { "qty", 50 },
                    { "tags", new BsonArray {
                          "red", "blank"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "paper" },
                    { "qty", 100 },
                    { "tags", new BsonArray {
                          "red", "blank", "plain"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "planner" },
                    { "qty", 75 },
                    { "tags", new BsonArray {
                          "blank", "red"
                      } },
                    { "dim_cm", new BsonArray {
                          22.85, 30
                      } }
                },
                new BsonDocument
                {
                    { "item", "postcard" },
                    { "qty", 45 },
                    { "tags", new BsonArray {
                          "blue"
                      } },
                    { "dim_cm", new BsonArray {
                          10, 15.25
                      } }
                }
                ,
                new BsonDocument
                {
                    { "item", "journal" },
                    { "qty", 25 },
                    { "size", new BsonDocument {
                          { "h", 14 }, { "w", 21 }, { "uom", "cm" }
                      } },
                    { "status", "A" }
                },
                new BsonDocument
                {
                    { "item", "notebook" },
                    { "qty", 50 },
                    { "size", new BsonDocument {
                          { "h", 8.5 }, { "w", 11 }, { "uom", "in" }
                      } },
                    { "status", "A" }
                },
                new BsonDocument
                {
                    { "item", "paper" },
                    { "qty", 100 },
                    { "size", new BsonDocument {
                          { "h", 8.5 }, { "w", 11 }, { "uom", "in" }
                      } },
                    { "status", "D" }
                },
                new BsonDocument
                {
                    { "item", "planner" },
                    { "qty", 75 },
                    { "size", new BsonDocument {
                          { "h", 22.85 }, { "w", 30 }, { "uom", "cm" }
                      } },
                    { "status", "D" }
                },
                new BsonDocument
                {
                    { "item", "postcard" },
                    { "qty", 45 },
                    { "size", new BsonDocument {
                          { "h", 10 }, { "w", 15.25 }, { "uom", "cm" }
                      } },
                    { "status", "A" }
                },
                new BsonDocument
                {
                    { "item", "journal" },
                    { "qty", 25 },
                    { "tags", new BsonArray {
                          "blank", "red"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "notebook" },
                    { "qty", 50 },
                    { "tags", new BsonArray {
                          "red", "blank"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "paper" },
                    { "qty", 100 },
                    { "tags", new BsonArray {
                          "red", "blank", "plain"
                      } },
                    { "dim_cm", new BsonArray {
                          14, 21
                      } }
                },
                new BsonDocument
                {
                    { "item", "planner" },
                    { "qty", 75 },
                    { "tags", new BsonArray {
                          "blank", "red"
                      } },
                    { "dim_cm", new BsonArray {
                          22.85, 30
                      } }
                },
                new BsonDocument
                {
                    { "item", "postcard" },
                    { "qty", 45 },
                    { "tags", new BsonArray {
                          "blue"
                      } },
                    { "dim_cm", new BsonArray {
                          10, 15.25
                      } }
                },
                new BsonDocument
                {
                    { "item", "journal" },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 5 }
                          },
                          new BsonDocument {
                              { "warehouse", "C" }, { "qty", 15 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "notebook" },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "C" }, { "qty", 5 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "paper" },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 60 }
                          },
                          new BsonDocument {
                              { "warehouse", "B" }, { "qty", 15 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "planner" },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 40 }
                          },
                          new BsonDocument {
                              { "warehouse", "B" }, { "qty", 5 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "postcard" },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "B" }, { "qty", 15 }
                          },
                          new BsonDocument {
                              { "warehouse", "C" }, { "qty", 35 }
                          }
                      } }
                }, new BsonDocument
                {
                    { "item", "journal" },
                    { "status", "A" },
                    { "size", new BsonDocument {
                          { "h", 14 }, { "w", 21 }, { "uom", "cm" }
                      } },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 5 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "notebook" },
                    { "status", "A" },
                    { "size", new BsonDocument {
                          { "h", 8.5 }, { "w", 11 }, { "uom", "in" }
                      } },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "C" }, { "qty", 5 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "paper" },
                    { "status", "D" },
                    { "size", new BsonDocument {
                          { "h", 8.5 }, { "w", 11 }, { "uom", "in" }
                      } },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 60 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "planner" },
                    { "status", "D" },
                    { "size", new BsonDocument {
                          { "h", 22.85 }, { "w", 30 }, { "uom", "cm" }
                      } },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "A" }, { "qty", 40 }
                          }
                      } }
                },
                new BsonDocument
                {
                    { "item", "postcard" },
                    { "status", "A" },
                    { "size", new BsonDocument {
                          { "h", 10 }, { "w", 15.25 }, { "uom", "cm" }
                      } },
                    { "instock", new BsonArray
                      {
                          new BsonDocument {
                              { "warehouse", "B" }, { "qty", 15 }
                          },
                          new BsonDocument {
                              { "warehouse", "C" }, { "qty", 35 }
                          }
                      } }
                },
                new BsonDocument {
                    { "_id", 1 }, { "item", BsonNull.Value }
                },
                new BsonDocument {
                    { "_id", 2 }
                }
            };
            MongoDBService mongoDBService = new MongoDBService();

            mongoDBService.InsertManyDocument(documents);
        }
        private void CalculateFastK_MR(int dataCount)
        {
            if (dataCount < NumberOfData + FastKPeriod - 1)
            {
                NumberOfData = dataCount - FastKPeriod + 1;
            }

            var limit  = FastKPeriod + NumberOfData - 1;
            var filter = new BsonDocument {
                { "Kod", Code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(TargetDate)) }
            };
            var sort       = new BsonDocument("Tarih", -1);
            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };

            BsonJavaScript mapper = new BsonJavaScript(@"
                function() {
	                if (!equalityFunction(this.Tarih, limitDate) && this.Tarih < limitDate)
		                return;
	                else if (!equalityFunction(this.Tarih, lastDate) && this.Tarih > lastDate)
		                return;
	
	                var dateIndex = binarySearch(dates, this.Tarih);

	                if (dateIndex == -1)
		                return;
	
	                for (var i = 0; i < period && dateIndex >= 0; i++, dateIndex--) {
		                if (dates[dateIndex] > startingDate || equalityFunction(dates[dateIndex], startingDate))
			                emit(dates[dateIndex], {close: this.Kapanis, low: this.Dusuk, high: this.Yuksek});
	                }
                }
            ");

            BsonJavaScript reducer = new BsonJavaScript(@"
                function(key, values) {
                    var result = {close: values[0].close, low: values[0].low, high: values[0].high};
                    for (var i = 1; i < values.length; i++) {
                        result.low = values[i].low < result.low ? values[i].low : result.low;
                        result.high = values[i].high > result.high ? values[i].high : result.high;
                    }
                    return result;
                }
            ");

            BsonJavaScript finalizer = new BsonJavaScript(@"
                function(key, reducedValue) {
                    reducedValue = 100 * (reducedValue.close - reducedValue.low) / (reducedValue.high - reducedValue.low);
                    return reducedValue;
                }
            ");

            var startingDate = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, NumberOfData - 1).GetElement(0).Value.ToLocalTime();
            var lastDate     = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();
            var limitDate    = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, limit - 1).GetElement(0).Value.ToLocalTime();
            var dates        = IndicatorService.GetData(Code, TargetDate, "Tarih", limit).Select(p => p.GetElement(0).Value.ToLocalTime()).ToArray();
            var scope        = new BsonDocument {
                { "startingDate", startingDate }, { "lastDate", lastDate }, { "limitDate", limitDate }, { "period", FastKPeriod }, { "numberOfData", NumberOfData }, { "binarySearch", MapReduceHelpers.BinarySearch }, { "equalityFunction", MapReduceHelpers.IsDatesEqual }, { "dates", new BsonArray(dates) }
            };

            var options = new MapReduceOptions <BsonDocument, BsonDocument>()
            {
                Filter        = filter,
                Sort          = sort,
                Scope         = scope,
                OutputOptions = MapReduceOutputOptions.Replace("stochasticsOut", "financialData", false),
                Finalize      = finalizer
            };

            FastK = new double[NumberOfData];
            var resultSet = MongoDBService.GetService().MapReduceMany(mapper, reducer, options);

            for (int i = 0, j = resultSet.Count - 1; i < NumberOfData; i++, j--)
            {
                FastK[i] = resultSet.ElementAt(j).GetElement(1).Value.ToDouble();
            }
        }
Example #25
0
        public async Task Post([FromBody] EstudianteModel estudiante)
        {
            var mongoDBService = new MongoDBService("Usuarios", "estudiantes", "mongodb://localhost:27017");

            await mongoDBService.InsertEstudiante(estudiante);
        }
Example #26
0
        public static double[] WsrMR(string code, DateTime targetDate, int period = 14, int numberOfData = 1)
        {
            if (period <= 0)
            {
                throw new IndicatorException("Period must be positive.");
            }
            else if (numberOfData <= 0)
            {
                throw new IndicatorException("Number of data to be processed must be positive.");
            }

            int dataCount = IndicatorService.DataCount(code, targetDate);

            if (dataCount < period)
            {
                throw new IndicatorException(IndicatorException.DATA_NOT_ENOUGH_MESSAGE);
            }

            if (dataCount < numberOfData + period - 1)
            {
                numberOfData = dataCount - period + 1;
            }

            var limit  = period + numberOfData - 1;
            var filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
            };
            var sort       = new BsonDocument("Tarih", -1);
            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };

            BsonJavaScript mapper = new BsonJavaScript(@"
                function() {
	                if (!equalityFunction(this.Tarih, limitDate) && this.Tarih < limitDate)
		                return;
	                else if (!equalityFunction(this.Tarih, lastDate) && this.Tarih > lastDate)
		                return;
	
	                var dateIndex = binarySearch(dates, this.Tarih);

	                if (dateIndex == -1)
		                return;
	
	                for (var i = 0; i < period && dateIndex >= 0; i++, dateIndex--) {
		                if (dates[dateIndex] > startingDate || equalityFunction(dates[dateIndex], startingDate))
			                emit(dates[dateIndex], {close: this.Kapanis, low: this.Dusuk, high: this.Yuksek});
	                }
                }
            ");

            BsonJavaScript reducer = new BsonJavaScript(@"
                function(key, values) {
                    var result = {close: values[0].close, low: values[0].low, high: values[0].high};
                    for (var i = 1; i < values.length; i++) {
                        result.low = values[i].low < result.low ? values[i].low : result.low;
                        result.high = values[i].high > result.high ? values[i].high : result.high;
                    }
                    return result;
                }
            ");

            BsonJavaScript finalizer = new BsonJavaScript(@"
                function(key, reducedValue) {
                    reducedValue = -100 * (reducedValue.high - reducedValue.close) / (reducedValue.high - reducedValue.low);
                    return reducedValue;
                }
            ");

            var startingDate = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, numberOfData - 1).GetElement(0).Value.ToLocalTime();
            var lastDate     = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();
            var limitDate    = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, limit - 1).GetElement(0).Value.ToLocalTime();
            var dates        = IndicatorService.GetData(code, targetDate, "Tarih", limit).Select(p => p.GetElement(0).Value.ToLocalTime()).ToArray();
            var scope        = new BsonDocument {
                { "startingDate", startingDate }, { "lastDate", lastDate }, { "limitDate", limitDate }, { "period", period }, { "numberOfData", numberOfData }, { "binarySearch", MapReduceHelpers.BinarySearch }, { "equalityFunction", MapReduceHelpers.IsDatesEqual }, { "dates", new BsonArray(dates) }
            };

            var options = new MapReduceOptions <BsonDocument, BsonDocument>()
            {
                Filter        = filter,
                Sort          = sort,
                Scope         = scope,
                OutputOptions = MapReduceOutputOptions.Replace("wsrOut", "financialData", false),
                Finalize      = finalizer
            };

            double[] wsr       = new double[numberOfData];
            var      resultSet = MongoDBService.GetService().MapReduceMany(mapper, reducer, options);

            for (int i = 0, j = resultSet.Count - 1; i < numberOfData; i++, j--)
            {
                wsr[i] = resultSet.ElementAt(j).GetElement(1).Value.ToDouble();
            }

            return(wsr);
        }
Example #27
0
        public void Update()
        {
            MongoDBService mongoDBService = new MongoDBService();

            mongoDBService.Update();
        }
Example #28
0
        public static double[] WeightedMR(string code, DateTime targetDate, int period = 14, int numberOfData = 30)
        {
            if (period <= 0)
            {
                throw new IndicatorException("Periyot pozitif sayı olmalıdır.");
            }
            else if (numberOfData <= 0)
            {
                throw new IndicatorException("Gösterilecek veri sayısı pozitif sayı olmalıdır.");
            }

            int dataCount = IndicatorService.DataCount(code, targetDate);

            if (dataCount < period)
            {
                throw new IndicatorException(IndicatorException.DATA_NOT_ENOUGH_MESSAGE);
            }

            if (dataCount < numberOfData + period - 1)
            {
                numberOfData = dataCount - period + 1;
            }

            int    limit       = numberOfData + period - 1;
            double denominator = (period * (period + 1)) >> 1;

            var filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
            };
            var sort = new BsonDocument("Tarih", -1);

            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };
            var startingDate = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, numberOfData - 1).GetElement(0).Value.ToLocalTime();
            var lastDate     = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();
            var limitDate    = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, limit - 1).GetElement(0).Value.ToLocalTime();
            var dates        = IndicatorService.GetData(code, targetDate, "Tarih", limit).Select(p => p.GetElement(0).Value.ToLocalTime()).ToArray();

            MapReduceOptions <BsonDocument, BsonDocument> options = new MapReduceOptions <BsonDocument, BsonDocument>
            {
                Filter = new BsonDocument {
                    { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
                },
                Sort          = new BsonDocument("Tarih", -1),
                OutputOptions = MapReduceOutputOptions.Replace("wmaOut", "financialData", false),
                Scope         = new BsonDocument {
                    { "startingDate", startingDate }, { "lastDate", lastDate }, { "limitDate", limitDate }, { "period", period }, { "denominator", denominator }, { "numberOfData", numberOfData }, { "binarySearch", MapReduceHelpers.BinarySearch }, { "equalityFunction", MapReduceHelpers.IsDatesEqual }, { "dates", new BsonArray(dates) }
                }
            };

            double[]       avg;
            BsonJavaScript mapper = new BsonJavaScript(@"
                function() {
	                if (!equalityFunction(this.Tarih, limitDate) && this.Tarih < limitDate)
		                return;
	                else if (!equalityFunction(this.Tarih, lastDate) && this.Tarih > lastDate)
		                return;
	
	                var dateIndex;
	
	                dateIndex = binarySearch(dates, this.Tarih);
	                if (dateIndex == -1)
		                return;
	
	                var factor = period;
	                for (var i = 0; i < period && dateIndex >= 0; i++, dateIndex--) {
		                if (dates[dateIndex] > startingDate || equalityFunction(dates[dateIndex], startingDate))
			                emit(dates[dateIndex], this.Kapanis * factor);
		                factor--;
	                }
                }
            ");

            BsonJavaScript reducer = new BsonJavaScript(@"
                function(key, values) {
	                return Array.sum(values);
                }
            ");

            BsonJavaScript finalizer = new BsonJavaScript(@"
                function(key, reducedValue) {
	                return reducedValue / denominator;
                }
            ");

            options.Finalize = finalizer;

            List <BsonDocument> resultSet = MongoDBService.GetService().MapReduceMany(mapper, reducer, options);

            avg = new double[numberOfData];

            for (int i = 0, j = numberOfData - 1; i < numberOfData; i++, j--)
            {
                avg[i] = resultSet.ElementAt(j).GetElement(1).Value.ToDouble();
            }

            return(avg);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest request,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function [SimpleLog] processed a request.");

            string connectionStringMSSQL   = Environment.GetEnvironmentVariable("ConnectionStringMSQSQL.SimpleLog.HttpTrigger");
            string connectionStringMongoDB = Environment.GetEnvironmentVariable("ConnectionStringMongoDB.SimpleLog.HttpTrigger");

            ;
            var toSaveMSSQL   = !string.IsNullOrEmpty(connectionStringMSSQL);
            var toSaveMongoDB = !string.IsNullOrEmpty(connectionStringMongoDB);

            if (!toSaveMSSQL && !toSaveMongoDB)
            {
                var errorMessageConnectionString = "the connection string is empty.";
                log.LogError(errorMessageConnectionString);
                return(new ObjectResult(new { Error = errorMessageConnectionString })
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError
                });
            }

            string requestBody = await new StreamReader(request.Body).ReadToEndAsync();
            var    viewModel   = JsonConvert.DeserializeObject <SimpleLogViewModel>(requestBody);

            var entity = new SimpleLogEntity(viewModel.OurClientId, viewModel.ApplicationId, viewModel.LogLevel, viewModel.Description, viewModel.Json);

            if (entity.HasNotification())
            {
                return(new BadRequestObjectResult(entity.GetNotification()));
            }

            var mssql   = new MSSQLService(connectionStringMSSQL);
            var mongoDB = new MongoDBService(connectionStringMongoDB);

            if (!(request.Headers["X-Sync-Request"].ToString() == "true"))
            {
                if (toSaveMSSQL)
                {
                    _ = mssql.SaveAsync(log, entity);
                }

                if (toSaveMongoDB)
                {
                    _ = mongoDB.SaveAsync(log, entity);
                }

                return(new CreatedResult(
                           GetResourceUrl(request, entity.Id), new
                {
                    Message = "Event sent.",
                    ResourceId = entity.Id
                }));
            }

            var savedMSSQL = false;

            if (toSaveMSSQL)
            {
                savedMSSQL = await mssql.SaveAsync(log, entity);
            }

            var savedMongoDB = false;

            if (toSaveMongoDB)
            {
                savedMongoDB = await mongoDB.SaveAsync(log, entity);
            }

            var conditionBoth    = ((toSaveMSSQL && savedMSSQL) && (toSaveMongoDB && savedMongoDB));
            var conditionMSQSQL  = !toSaveMongoDB && (toSaveMSSQL && savedMSSQL);
            var conditionMongoDB = !toSaveMSSQL && (toSaveMongoDB && savedMongoDB);

            if (conditionBoth || conditionMSQSQL || conditionMongoDB)
            {
                return(new CreatedResult(
                           GetResourceUrl(request, entity.Id), new
                {
                    Message = "The object was saved in the database.",
                    ResourceId = entity.Id
                }));
            }
            else
            {
                return(new UnprocessableEntityObjectResult(new
                {
                    Error = $"The object could not be saved to the database."
                }));
            }
        }
Example #30
0
        public static double[] ExponentialMR(string code, DateTime targetDate, int period = 14, int numberOfData = 30)
        {
            if (period <= 0)
            {
                throw new IndicatorException("Period must be positive.");
            }

            int dataCount = IndicatorService.DataCount(code, targetDate);

            if (dataCount < numberOfData)
            {
                numberOfData = dataCount;
            }

            double alpha = 2.0 / (1 + period);
            double beta  = 1 - alpha;
            double minimumCoefficient = 0.001;

            BsonJavaScript mapper = new BsonJavaScript(@"
                function() {
	                if (!equalityFunction(this.Tarih, limitDate) && this.Tarih < limitDate)
		                return;
	                else if (!equalityFunction(this.Tarih, lastDate) && this.Tarih > lastDate)
		                return;
	                var dateIndex = binarySearch(dates, this.Tarih);
	                if (dateIndex == -1)
		                return;
	                
                    var epoch = Math.log(minimumCoefficient / (alpha * this.Kapanis)) / Math.log(beta);
                    var value;
	                if (dateIndex == numberOfData-1) {
		                value = this.Kapanis;
		                for (var i = dateIndex, j = 0; j < epoch && i >= 0; i--, j++) {
			                emit(dates[i], value);
			                value = value * beta;
		                }
	                } else {
		                value = this.Kapanis * alpha;
		                for (var i = dateIndex, j = 0; j < epoch && i >= 0; i--, j++) {
			                emit(dates[i], value);
			                value = value * beta;
		                }
	                }
                }
            ");

            BsonJavaScript reducer = new BsonJavaScript(@"
                function(key,values){
                    return Array.sum(values);
                }
            ");

            var filter = new BsonDocument {
                { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
            };
            var sort         = new BsonDocument("Tarih", -1);
            var mongoService = MongoDBService.GetService();

            var projection = new BsonDocument {
                { "_id", 0 }, { "Tarih", 1 }
            };
            var lastDate  = MongoDBService.GetService().FindOneSortProject(filter, sort, projection).GetElement(0).Value.ToLocalTime();
            var limitDate = MongoDBService.GetService().FindOneSortProjectSkip(filter, sort, projection, numberOfData - 1).GetElement(0).Value.ToLocalTime();
            var dates     = IndicatorService.GetData(code, targetDate, "Tarih", numberOfData).Select(p => p.GetElement(0).Value.ToLocalTime()).ToArray();
            var scope     = new BsonDocument {
                { "numberOfData", numberOfData }, { "minimumCoefficient", minimumCoefficient }, { "alpha", alpha }, { "beta", beta }, { "lastDate", lastDate }, { "limitDate", limitDate }, { "dates", new BsonArray(dates) }, { "binarySearch", MapReduceHelpers.BinarySearch }, { "equalityFunction", MapReduceHelpers.IsDatesEqual }
            };

            MapReduceOptions <BsonDocument, BsonDocument> options = new MapReduceOptions <BsonDocument, BsonDocument>
            {
                Filter        = filter,
                Sort          = sort,
                Scope         = scope,
                OutputOptions = MapReduceOutputOptions.Replace("emaOut", "financialData", false)
            };

            double[] values = MongoDBService.GetService().MapReduceMany(mapper, reducer, options).Select(p => p.GetElement("value").Value.ToDouble()).ToArray();
            Array.Reverse(values);
            return(values);
        }
 public static int DataCount(string code, DateTime targetDate)
 {
     return(MongoDBService.GetService().Count(new BsonDocument {
         { "Kod", code }, { "Tarih", new BsonDocument("$lte", new BsonDateTime(targetDate)) }
     }));
 }