Exemplo n.º 1
0
 private void Research(DownloadFinished par)
 {
     for (int i = 0; i < par.Responces.Count; i++)
     {
         par.Responces[i].FillDayValues();
     }
 }
Exemplo n.º 2
0
        private void CreateSeries(DownloadFinished par)
        {
            List <FundResponce> ResponcesBeforeBuy = new List <FundResponce>();

            for (int i = 0; i < par.Responces.Count; i++)
            {
                par.Responces[i].Color = HtmlCreator.ColorPallete[i % HtmlCreator.ColorPallete.Length];
                int BuyDateIndex = par.Responces[i].FillDayValues();
                if (BuyDateIndex > 0)
                {
                    ResponcesBeforeBuy.Add(par.Responces[i].CreateBeforeBuyResonce(BuyDateIndex));
                }
            }
            par.Responces.AddRange(ResponcesBeforeBuy);

            CalculateAverageSerie(ref par.Responces);
        }
Exemplo n.º 3
0
        string CreatePage(DownloadFinished df)
        {
            string FundsList; string ValuesList; string GroupsList = "";

            if (string.IsNullOrEmpty(Template))
            {
                return("Template NotFound");
            }

            System.Globalization.NumberFormatInfo myInv = System.Globalization.NumberFormatInfo.InvariantInfo;

            foreach (string gn in FundGroups.GroupNames)
            {
                if (gn == df.FundGroupName)
                {
                    GroupsList += "<option value='" + gn + "' selected>" + gn + "</option>";
                }
                else
                {
                    GroupsList += "<option value='" + gn + "'>" + gn + "</option>";
                }
            }

            FundsList = ", colors: [";
            for (int i = 0; i < df.Responces.Count; i++)
            {
                if (i != 0)
                {
                    FundsList += ",";
                }
                FundsList += df.Responces[i].Color;
            }
            FundsList += "], series: {";

            for (int i = 0; i < df.Responces.Count; i++)
            {
                if (i != 0)
                {
                    FundsList += ",";
                }
                if (df.Responces[i].DotStyle)
                {
                    FundsList += i.ToString() + ": { lineWidth: 1, lineDashStyle: [4, 4] }";
                }
                else
                {
                    if (df.Responces[i].FundId == -1)
                    {
                        FundsList += i.ToString() + ": { lineWidth: 2 }";
                    }
                    else
                    {
                        FundsList += i.ToString() + ": { lineWidth: 1 }";
                    }
                }
            }
            FundsList += "}";

            List <string> vl = new List <string>();

            vl.Add("var data = google.visualization.arrayToDataTable([['X'");
            for (int f = 0; f < df.Responces.Count; f++)
            {
                if (df.Responces[f].FundId == -1)
                {
                    vl.Add(",'Average']");
                }
                else
                {
                    vl.Add(", '" + df.Responces[f].FundId.ToString() + "'");
                }
            }

            List <DateTime> dates = (from fr in df.Responces
                                     from dv in fr.DayValues
                                     select dv.Date)
                                    .Distinct().OrderBy(x => x).ToList();

            for (int d = 0; d < dates.Count; d++)
            {
                vl.Add(string.Format(", [new Date ({0}, {1}, {2})", dates[d].Year, dates[d].Month - 1, dates[d].Day));
                for (int f = 0; f < df.Responces.Count; f++)
                {
                    DayValue dv = df.Responces[f].DayValues.FirstOrDefault(x => x.Date == dates[d]);
                    if (dv != null)
                    {
                        vl.Add(", " + dv.Percent.ToString(myInv));
                    }
                    else
                    {
                        vl.Add(", ");
                    }
                }
                vl.Add("]");
            }
            vl.Add(" ]);");
            ValuesList = string.Join(null, vl);

            string FromValue = df.From.ToString(Fund.NeDateFormat);
            string ToValue   = df.To.ToString(Fund.NeDateFormat);

            string content = Template
                             .Replace("<FundsList/>", FundsList)
                             .Replace("<ValuesList/>", ValuesList)
                             .Replace("//##ValuesList##", ValuesList)
                             .Replace("//##Options##", FundsList)
                             .Replace("//##GroupsList##", GroupsList)
                             .Replace("FromValue", FromValue)
                             .Replace("ToValue", ToValue);

            return(content);
        }
Exemplo n.º 4
0
        private void InitialReceives()
        {
            Receive <StartDownload>(par =>
            {
                try
                {
                    _stopCommand = false;
                    _requests.Clear();
                    DF = new DownloadFinished();
                    DownloadManager.status = Status.InProcess;

                    FundGroup fg = FundGroups.Groups?.FirstOrDefault(x => x.Name == (par.FundGroupName ?? "nosale"));
                    if (fg == null)
                    {
                        Sender.Tell(new FundGroupNotFound());
                    }
                    else
                    {
                        DF.From          = par.From ?? new DateTime(2020, 03, 29);
                        DF.To            = par.To ?? DateTime.Now;
                        DF.FundGroupName = fg.Name;

                        FundRequest cur;
                        foreach (Fund f in fg.Funds)
                        {
                            _requests.Add((cur = new FundRequest
                            {
                                FundId = f.Id,
                                From = DF.From,
                                To = DF.To,
                                Tag = f,
                                status = Status.InProcess,
                                retry = 1,
                            }));
                            if (_downloaderRef != null)
                            {
                                _downloaderRef.Tell(cur);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("DownloadManager:StartDownload " + ex.Message);
                }
            });
            Receive <Stop>(job => { _stopCommand = true; });
            Receive <FundResponce>(responce =>
            {
                try
                {
                    if (responce != null)
                    {
                        DF.Responces.Add(responce);
                        FundRequest req = _requests.FirstOrDefault(x => x.FundId == responce.FundId);
                        if (req != null)
                        {
                            req.status = Status.Successfuly;
                        }
                        if (_requests.Count(x => x.status == Status.Successfuly) == _requests.Count)
                        {
                            status = Status.Successfuly;
                            Context.Parent.Tell(DF);
                        }
                        else if (_requests.Count(x => x.status == Status.InProcess)
                                 + _requests.Count(x => x.status == Status.Failed && x.retry < 3) == 0)
                        {
                            status = Status.Failed;
                        }
                        else
                        {
                            status = Status.InProcess;
                        }
                    }

                    // BusinesLogic.Log.Logging(BusinesLogic.OP, "FundResponce");
                    // responce.SaveToFile();
                    // MainWindowViewModel.VP.AddNewSerie(responce);
                }
                catch (Exception ex)
                {
                    Log.Error("DownloadManager:FundResponce " + ex.Message);
                }
            });
            Receive <FailedFun>(res =>
            {
                try
                {
                    if (res != null)
                    {
                        FundRequest req = _requests.FirstOrDefault(x => x.FundId == res.FundId);
                        if (req != null)
                        {
                            req.status = Status.Failed;
                            req.retry++;
                            if (!_stopCommand && req.retry <= 3)
                            {
                                _downloaderRef.Tell(req);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("DownloadManager:FailedFun " + ex.Message);
                }
            });
            Receive <StartResearch_Step1>(par =>
            {
                try
                {
                    _stopCommand = false;
                    _requests.Clear();
                    DF = new DownloadFinished_Research_Step1();
                    DownloadManager.status = Status.InProcess;

                    FundGroup fg = FundGroups.Groups?.FirstOrDefault(x => x.Name == Fund.AllGroupName);
                    if (fg == null)
                    {
                        Sender.Tell(new FundGroupNotFound());
                    }
                    else
                    {
                        DF.From          = DateTime.Now.AddDays(-Research.CheckPeriod_Days - 2);
                        DF.To            = DateTime.Now;
                        DF.FundGroupName = fg.Name;

                        FundRequest cur;
                        foreach (Fund f in fg.Funds)
                        {
                            _requests.Add((cur = new FundRequest
                            {
                                FundId = f.Id,
                                From = DF.From,
                                To = DF.To,
                                Tag = f,
                                status = Status.InProcess,
                                retry = 1,
                            }));
                            if (_downloaderRef != null)
                            {
                                _downloaderRef.Tell(cur);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Error("DownloadManager:StartResearch_Step1 " + ex.Message);
                }
            });
        }
Exemplo n.º 5
0
        string CreatePage_0(DownloadFinished df)
        {
            string FundsList; string ValuesList; string GroupsList = "";

            if (string.IsNullOrEmpty(Template))
            {
                return("Template NotFound");
            }

            System.Globalization.NumberFormatInfo myInv = System.Globalization.NumberFormatInfo.InvariantInfo;

            foreach (string gn in FundGroups.GroupNames)
            {
                if (gn == df.FundGroupName)
                {
                    GroupsList += "<option value='" + gn + "' selected>" + gn + "</option>";
                }
                else
                {
                    GroupsList += "<option value='" + gn + "'>" + gn + "</option>";
                }
            }

            FundsList = ", colors: [";
            for (int i = 0; i < df.Responces.Count; i++)
            {
                FundsList += df.Responces[i].Color + ",";
            }

            // int ResIndex = 0;
            // while (ResIndex < df.Responces.Count)
            // {
            //     FundsList += ColorPallete[ResIndex % ColorPallete.Length] + ",";
            //     ResIndex++;
            // }
            FundsList += "'#000000'], series: {";

            for (int i = 0; i < df.Responces.Count; i++)
            {
                if (df.Responces[i].DotStyle)
                {
                    FundsList += i.ToString() + ": { lineWidth: 1, lineDashStyle: [4, 4] },";
                }
                else
                {
                    FundsList += i.ToString() + ": { lineWidth: 1 },";
                }
            }

            FundsList += df.Responces.Count.ToString() + ": { lineWidth: 2 }}";

            // ResIndex = 0;
            // while (ResIndex < df.Responces.Count)
            // {
            //     FundsList += ResIndex.ToString() + ": { lineWidth: 1 },";
            //     ResIndex++;
            // }
            // FundsList += ResIndex.ToString() + ": { lineWidth: 2 }}";

            // series: {
            //  0: { lineWidth: 1 },
            //  1: { lineWidth: 2 },
            //  2: { lineWidth: 4 },
            //  3: { lineWidth: 8 },
            //  4: { lineWidth: 16 },
            //  5: { lineWidth: 24 }
            // },

            List <string> vl = new List <string>();

            vl.Add("var data = google.visualization.arrayToDataTable([['X'");
            // ValuesList = "var data = google.visualization.arrayToDataTable([['X'";
            for (int f = 0; f < df.Responces.Count; f++)
            {
                vl.Add(", '" + df.Responces[f].FundId.ToString() + "'");
            }
            // ValuesList += ", '" + res[f].FundId.ToString() + "'";
            vl.Add(",'Average']");
            // ValuesList += ",'Average']";
            List <DateTime> dates = (from fr in df.Responces
                                     from dv in fr.DayValues
                                     select dv.Date)
                                    .Distinct().OrderBy(x => x).ToList();
            float averValue;

            for (int d = 0; d < dates.Count; d++)
            {
                averValue = 0;
                vl.Add(string.Format(", [new Date ({0}, {1}, {2})", dates[d].Year, dates[d].Month - 1, dates[d].Day));
                // string curValue = string.Format(", [new Date ({0}, {1}, {2})", dates[d].Year, dates[d].Month - 1, dates[d].Day);
                if (d == 0)
                {
                    for (int f = 0; f < df.Responces.Count; f++)
                    {
                        vl.Add(",0");
                    }
                }
                else
                {
                    for (int f = 0; f < df.Responces.Count; f++)
                    {
                        DayValue dv = df.Responces[f].DayValues.FirstOrDefault(x => x.Date == dates[d]);
                        if (dv != null)
                        {
                            vl.Add(", " + dv.Percent.ToString(myInv));
                            // curValue += ", " + dv.Percent.ToString(myInv);
                            averValue += dv.Percent;
                        }
                        else
                        {
                            vl.Add(", ");
                            // curValue += ", ";
                            int step = 1; DayValue dv2 = null; DateTime prevDate;
                            do
                            {
                                prevDate = dates[d].AddDays(-step);
                                dv2      = df.Responces[f].DayValues.FirstOrDefault(x => x.Date == prevDate);
                                step++;
                            } while (dv2 == null && step < 30 && prevDate >= df.From);
                            if (dv2 != null)
                            {
                                averValue += dv2.Percent;
                            }
                        }
                    }
                }
                vl.Add(", " + (averValue / df.Responces.Count).ToString(myInv) + "]");
                // ValuesList += ", " + curValue + (averValue / res.Count).ToString(myInv) + "]"; //add fiction series
            }
            vl.Add(" ]);");
            // ValuesList = ValuesList.Substring(0, ValuesList.Length - 2) + " ]);";
            ValuesList = string.Join(null, vl);


            string FromValue = df.From.ToString(Fund.NeDateFormat);
            string ToValue   = df.To.ToString(Fund.NeDateFormat);

            string content = Template
                             .Replace("<FundsList/>", FundsList)
                             .Replace("<ValuesList/>", ValuesList)
                             .Replace("//##ValuesList##", ValuesList)
                             .Replace("//##Options##", FundsList)
                             .Replace("//##GroupsList##", GroupsList)
                             .Replace("FromValue", FromValue)
                             .Replace("ToValue", ToValue);

            return(content);
        }