Exemple #1
0
        public int DayValuesReorganize()
        {
            MinValue = 0;
            if (DayValues != null && DayValues.Count > 0)
            {
                DayValues = DayValues.OrderBy(x => x.Date).ToList();
                for (int i = 0; i < DayValues.Count; i++)
                {
                    DayValues[i].Index = i;
                }

                DayValue dvWithMinValue = DayValues[0];
                if (this.Tag.BuyDate.HasValue && this.Tag.BuyDate.Value > From && this.Tag.BuyDate.Value < To)
                {
                    dvWithMinValue = DayValues.FirstOrDefault(x => x.Date == this.Tag.BuyDate.Value);
                }

                MinValue = dvWithMinValue.Value;
                // Count = DayValues.Count;

                // for (int i = 0; i < DayValues.Count; i++)
                // DayValues[i].Percent=-100.0F + 100.0F * x.Value / MinValue;
                DayValues.Select(x => x.Percent = -100.0F + 100.0F * x.Value / MinValue).Count();
                return(dvWithMinValue.Index);
            }
            else
            {
                return(0);
            }
        }
Exemple #2
0
        public int FillDayValues()
        {
            List <string> parts = ParseWebResponce(0);

            foreach (string part in parts)
            {
                string[] Values = part.Split(new char[] { ',', ' ', '"' }, StringSplitOptions.RemoveEmptyEntries);
                DateTime Date;
                float    Value;

                if (!float.TryParse(Values[0], NumberStyles.Any, CultureInfo.InvariantCulture, out Value) ||
                    !DateTime.TryParseExact(Values[1], Tase.ResponceDateFormat, null, DateTimeStyles.None, out Date))
                {
                    continue;
                }
                DayValue dv = new DayValue {
                    Date = Date, Value = Value
                };

                DayValues.Add(dv);
            }

            DayValues = DayValues.OrderBy(x => x.Date).ToList();
            for (int i = DayValues.Count - 1; i > 0; i--)
            {
                int   DaysGap    = (int)(DayValues[i].Date - DayValues[i - 1].Date).TotalDays;
                float ValueDelta = (DayValues[i].Value - DayValues[i - 1].Value) / DaysGap;
                for (int d = 1; d < DaysGap; d++)
                {
                    DayValues.Add(new DayValue
                    {
                        Date  = DayValues[i - 1].Date.AddDays(d),
                        Value = DayValues[i - 1].Value + d * ValueDelta,
                    });
                }
            }
            // DayValues = DayValues.OrderBy(x => x.Date).ToList();
            // for (int i = 0; i < DayValues.Count; i++)
            //     DayValues[i].Index = i;

            //remove before bay date???
            // if (responce.Tag != null && responce.Tag.IdBuyed)
            //     for (int i = responce.DayValues.Count - 1; i >= 0; i--)
            //         if (responce.DayValues[i].Date < responce.Tag.BuyDate)
            //             responce.DayValues.RemoveAt(i);

            int BuyDateIndex = DayValuesReorganize();

            return(BuyDateIndex);
        }
Exemple #3
0
        private void CalculateAverageSerie(ref List <FundResponce> responces)
        {
            // System.Globalization.NumberFormatInfo myInv = System.Globalization.NumberFormatInfo.InvariantInfo;
            List <string> res      = new List <string>();
            FundResponce  AverData = new FundResponce
            {
                Color     = "'#000000'",
                DotStyle  = false,
                DayValues = new List <DayValue>(),
                FundId    = -1,
            };

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

            for (int d = 0; d < dates.Count; d++)
            {
                float PercentValue = 0; int ValuesCount = 0;
                for (int f = 0; f < responces.Count; f++)
                {
                    DayValue dv = responces[f].DayValues.FirstOrDefault(x => x.Date == dates[d]);
                    if (dv != null)
                    {
                        if (!responces[f].DotStyle)
                        {
                            PercentValue += dv.Percent;
                            ValuesCount++;
                        }
                    }
                }
                float Percent = ValuesCount > 0 ? PercentValue / ValuesCount : 0;
                AverData.DayValues.Add(new DayValue {
                    Date = dates[d], Index = d, Percent = Percent
                });
            }
            responces.Add(AverData);
        }
Exemple #4
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);
        }
Exemple #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);
        }