示例#1
0
        public static ChartInterval ToChartInterval(zChartInterval chartInterval)
        {
            string        sInterval = chartInterval.ToString();
            ChartInterval interval  = (ChartInterval)Enum.Parse(typeof(ChartInterval), sInterval, true);

            return(interval);
        }
示例#2
0
        public static zChartInterval FromChartInterval(ChartInterval chartInterval)
        {
            string         sInterval = chartInterval.ToString();
            zChartInterval interval  = (zChartInterval)Enum.Parse(typeof(zChartInterval), sInterval, true);

            return(interval);
        }
示例#3
0
        public ChartViewModel(ApplicationDbContext context, DbConnection dbConnection, ApplicationUser user, bool IsMarketeer, ChartInterval interval)
        {
            Interval = interval;

            _dbConnection = dbConnection;

            string chartSP = "GetChartData", chartStatsSP = "GetChartStats";

            if (IsMarketeer)
            {
                chartSP      = "Marketeer_GetChartData";
                chartStatsSP = "Marketeer_GetChartStats";
            }

            var data = _dbConnection.Query(chartSP, new { chartType = (int)interval, user = user.Id },
                                           null, true, null, System.Data.CommandType.StoredProcedure)
                       .ToDictionary(x => x.Label, x => x.Ratings);

            XLables = data.Keys.Cast <string>().ToList();
            Values  = data.Values.Cast <double>().ToList();

            var stats = _dbConnection.Query(chartStatsSP, new { chartType = (int)interval, user = user.Id },
                                            null, true, null, System.Data.CommandType.StoredProcedure);

            if (stats.Any())
            {
                var stat = stats.First();
                RatedEmails    = stat.RatedEmails.ToString();
                AverageScore   = stat.AverageScore.ToString();
                CommunityMatch = stat.CommunityMatch?.ToString();
                Evaluators     = stat.Evaluators?.ToString();
            }
        }
        public AnalyticsViewModel(ApplicationDbContext db, DbConnection dbConnection,
                                  UserManager <ApplicationUser> userManager, ApplicationUser user, ChartInterval interval)
        {
            _context     = db;
            _userManager = userManager;

            ChartData = new ChartViewModel(db, dbConnection, user, true, interval);

            var sb        = user.Balance.ToString("F");
            var separator = '.';

            var i = sb.IndexOf('.');

            if (i < 0)
            {
                separator = ',';
                i         = sb.IndexOf(',');
            }

            string sf = string.Empty, sp = string.Empty;

            if (i > 0)
            {
                sf = sb.Substring(0, sb.IndexOf(separator));
                sp = sb.Substring(sb.IndexOf(separator) + 1);
                BalanceFullPart    = int.Parse(sf);
                BalancePartialPart = int.Parse(sp);
            }

            var pub = _context.Providers.Where(x => x.Owner == user).FirstOrDefault();

            if (pub == null)
            {
                return;
            }

            IsProviderSet = true;

            _context.Entry(pub)
            .Collection(s => s.Campaigns)
            .Load();


            if (pub.Campaigns.Any())
            {
                RatedCampaigns = pub.Campaigns.Count();

                var budget = pub.Campaigns.Sum(x => x.Budget);

                if (_context.Statistics.Any())
                {
                    var rewardPool = (from c in pub.Campaigns
                                      join s in _context.Statistics on c.ID equals s.Campaign.ID
                                      select s.Reward).Sum();

                    //AverageScore = (from c in pub.Campaigns
                    //                join s in _db.Statistics on c.ID equals s.Campaign.ID
                    //                select s.Rating).Average();

                    //Evaluations = (from c in pub.Campaigns
                    //               join s in _db.Statistics on c.ID equals s.Campaign.ID
                    //               select s.ID).Count();

                    RewardPoolStatus = budget - rewardPool;

                    var myHighestRatingsAverage = (from c in pub.Campaigns
                                                   join s in _context.Statistics on c.ID equals s.Campaign.ID
                                                   join cnt in _context.ContentTypes on c.ContentTypeID equals cnt.ID
                                                   group s by new { Publisher = pub.Name, s.Campaign.ID, cnt.Name } into g
                                                   orderby g.Average(x => x.Rating) descending
                                                   select new { pub = g.Key.Publisher, tp = g.Key.Name, score = g.Average(x => x.Rating) })
                                                  .FirstOrDefault();

                    List <Tuple <string, string, double> > standings = new List <Tuple <string, string, double> >();

                    if (myHighestRatingsAverage != null)
                    {
                        standings.Add(new Tuple <string, string, double>(myHighestRatingsAverage.pub, myHighestRatingsAverage.tp, myHighestRatingsAverage.score));

                        var all = (from c in _context.Campaigns
                                   join s in _context.Statistics on c.ID equals s.Campaign.ID
                                   join cnt in _context.ContentTypes on c.ContentTypeID equals cnt.ID
                                   where c.ContentType.Name == myHighestRatingsAverage.tp && pub.Name != myHighestRatingsAverage.pub
                                   group s by new { Publisher = pub.Name, s.Campaign.ID, cnt.Name } into g
                                   orderby g.Average(x => x.Rating) descending
                                   select new { pub = g.Key.Publisher, tp = g.Key.Name, score = g.Average(x => x.Rating) })
                                  .ToList();

                        if (all.Any())
                        {
                            all.ForEach(x => standings.Add(new Tuple <string, string, double>(x.pub, x.tp, x.score)));
                        }
                    }

                    Standings = standings;
                }
            }
        }
示例#5
0
        public void RequestChartData(ChartInterval interval)
        {
            this.Text = moMarket.Description;

            // Set EndDate to the current trading date.
            DateTime dtEndDate = moSelectedContract.GetTradeDate(DateTime.Now);
            DateTime dtStartDate;

            T4.API.ChartData.ChartInterval enBarInterval = ChartInterval.Hour;


            if (interval == ChartInterval.Day)
            {
                enBarInterval = ChartInterval.Day;

                // User select Day bars, load a month of them.
                dtStartDate = dtEndDate.AddMonths(-1);
            }
            else
            {
                //enBarInterval = ChartInterval.Hour;
                enBarInterval = ChartInterval.Minute;

                // User selected Hour bars, load a couple of days of them.
                dtStartDate = dtEndDate;

                // This little loop here will ensure that we load the previous trade date as well as today and will account for weekends
                // and holidays.
                while ((moSelectedContract.GetTradeDate(dtStartDate) == dtEndDate))
                {
                    dtStartDate = dtStartDate.AddDays(-1);
                }
            }

            // Create a BarInterval object to tell the API what bar interval we want.
            // So for example, if we wanted a 15 minute bar, we would do:  New T4.API.ChartData.BarInterval(ChartDataType.Minute, 15)
            //T4.API.ChartData.BarInterval oBarIntvl = new T4.API.ChartData.BarInterval(enBarInterval, 2);
            T4.API.ChartData.BarInterval oBarIntvl = new T4.API.ChartData.BarInterval(enBarInterval, 5);


            if (moMarket != null)
            {
                // A market was selected. Load the data for the selected market.

                // First, create a new ChartDataSeries. This object store the chart data from the server as well as keep it updated as live trades
                // come in. You REALLY should be careful to ensure that you properly Dispose this object when you are no longer using it.
                moBarData = new T4.API.ChartData.ChartDataSeries(moMarket, oBarIntvl, SessionTimeRange.Empty);

                moBarData.DataSeriesUpdated += moBarData_DataSeriesUpdated;
                moBarData.DataLoadComplete  += moBarData_DataLoadComplete;

                // Request the chart data.
                // LoadRealTimeChartData() takes only a start date. It will load all historical chart data from that date to now and will keep
                //    that data updated as trades get posted to the system.
                moBarData.LoadRealTimeChartData(dtStartDate);

                // Alternatively, LoadHistoricalChartData() takes a start and end date and simply only load historical chart data. This method does
                //    NOT keep the data updated as live trades come in.
                //moBarData.LoadHistoricalChartData(dtStartDate, dtEndDate)
            }
            else
            {
                // A market was not selected. Load "continuation" data.
                // The default contructor for ContinuationSettings instructs the API to create a long-term historical series of chart data
                //   for the contract by looking at the total traded volume for each day. The market that has the high trade volume is the
                //   market from which data will be pulled for that trade date. This is called a "volume continuation" and is the most common
                //   method of constructing such chart data sets for a contract. There are other types of continuations that you can create, however
                //   they won't be discussed in this example.
                T4.API.ChartData.ContinuationSettings oContinuation = new T4.API.ChartData.ContinuationSettings();

                // First, create a new ChartDataSeries. This object store the chart data from the server as well as keep it updated as live trades
                // come in. You REALLY should be careful to ensure that you properly Dispose this object when you are no longer using it.
                moBarData = new T4.API.ChartData.ChartDataSeries(moSelectedContract, oBarIntvl, SessionTimeRange.Empty, oContinuation);

                // Request the chart data.
                // LoadRealTimeChartData() takes only a start date. It will load all historical chart data from that date to now and will keep
                //    that data updated as trades get posted to the system.
                moBarData.LoadRealTimeChartData(dtStartDate);

                // Alternatively, LoadHistoricalChartData() takes a start and end date and simply only load historical chart data. This method does
                //    NOT keep the data updated as live trades come in.
                //moBarData.LoadHistoricalChartData(dtStartDate, dtEndDate)
            }
        }
        public DashboardViewModel(ApplicationDbContext context, DbConnection dbConnection,
                                  UserManager <ApplicationUser> userManager, ApplicationUser user, ChartInterval interval)
        {
            _context      = context;
            _dbConnection = dbConnection;

            var sb = user.Balance.ToString("F");

            var separator = '.';

            var i = sb.IndexOf('.');

            if (i < 0)
            {
                separator = ',';
                i         = sb.IndexOf(',');
            }

            string sf = string.Empty, sp = string.Empty;

            if (i > 0)
            {
                sf = sb.Substring(0, sb.IndexOf(separator));
                sp = sb.Substring(sb.IndexOf(separator) + 1);
                BalanceFullPart    = int.Parse(sf);
                BalancePartialPart = int.Parse(sp);
            }

            var interests = _context.Entry(user)
                            .Collection(s => s.Interests)
                            .Query()
                            .Select(p => p.ContentType.Name)
                            .ToList();

            FavouriteFields = interests;

            ChartData = new ChartViewModel(context, _dbConnection, user, false, interval);
        }