Пример #1
0
        private void load_data_2_grv()
        {
            string         v_path = Directory.GetCurrentDirectory();
            FacebookClient fb     = new FacebookClient(access_token);

            m_grv.AutoGenerateColumns = false;
            var roles = new List <cl_post>();

            string[] lines = System.IO.File.ReadAllLines(v_path + "\\postId.txt");
            for (int i = 0; i < lines.Count(); i++)
            {
                string post = lines[i].Trim();
                if (post.Contains(m_uid.Trim()))
                {
                    cl_post v_cl_post = new cl_post();
                    v_cl_post.fuid    = m_uid;
                    post              = post.Substring(m_uid.Length + 1, post.Length - m_uid.Length - 1);
                    v_cl_post.fpid    = post.Trim();
                    v_cl_post.content = lines[i + 2].Trim();
                    v_cl_post.fgid    = lines[i + 1].Trim();
                    roles.Add(v_cl_post);
                }
            }
            m_grv.DataSource = roles;
        }
Пример #2
0
        private void m_cmd_phan_tich_group_Click(object sender, EventArgs e)
        {
            try
            {
                #region variable
                decimal         count_like        = 0;
                decimal         count_date        = 0;
                decimal         count_post        = 0;
                decimal         count_comment     = 0;
                int             gold_hour         = 0;
                int             gold_hour_comment = 0;
                int             silver_hour       = 0;
                int             max_post          = 0;
                int             max_comment       = 0;
                int             min_post          = 1000;
                string          v_limit           = "";
                bool            name_exist        = false;
                List <DateTime> v_list_dat        = new List <DateTime>();
                #endregion
                reset_lbl();

                if (m_rdb_30.Checked)
                {
                    v_limit = "30";
                }
                else if (m_rdb_50.Checked)
                {
                    v_limit = "100";
                }
                else
                {
                    v_limit = "200";
                }

                FacebookClient fb  = new FacebookClient(globalInfo.access_token);
                string         gid = ((groups)m_lb_groups.SelectedItem).Id;

                dynamic        data      = fb.Get("/" + gid + "?fields=feed.limit(" + v_limit + ").fields(id,created_time,likes.fields(id),comments.fields(id,created_time,from))");
                var            feed      = (JsonObject)data["feed"];
                List <cl_post> post_list = new List <cl_post>();
                foreach (dynamic post in (JsonArray)feed["data"])
                {
                    cl_post v_p = new cl_post();
                    v_p.fpid        = (((JsonObject)post)["id"]).ToString();
                    v_p.create_time = (Facebook.DateTimeConvertor.FromIso8601FormattedDateTime((((JsonObject)post)["created_time"]).ToString()));

                    //----------------------------------------------------------
                    name_exist = checkNameExist(post, "likes");
                    if (name_exist)
                    {
                        var likes = (JsonObject)post["likes"];
                        var like  = (JsonArray)likes["data"];
                        foreach (var lk in like)
                        {
                            count_like += 1;
                        }
                    }
                    v_p.like_count = count_like;
                    //----------------------------------------------------------
                    name_exist = checkNameExist(post, "comments");
                    if (name_exist)
                    {
                        var comments = (JsonObject)post["comments"];
                        var comment  = (JsonArray)comments["data"];

                        foreach (var lk in comment)
                        {
                            DateTime create_time = Facebook.DateTimeConvertor.FromIso8601FormattedDateTime(((JsonObject)lk)["created_time"].ToString());
                            v_list_dat.Add(create_time);
                            count_comment += 1;
                        }
                    }
                    v_p.comment_count = count_comment;
                    //----------------------------------------------------------
                    post_list.Add(v_p);
                }

                //------------------------------------------------------------------------
                //post per day
                #region post per day
                foreach (var line in post_list.GroupBy(info => info.create_time.Date)
                         .Select(group => new
                {
                    Metric = group.Key,
                    Count = group.Count()
                })
                         .OrderBy(x => x.Metric))
                {
                    count_date += 1;
                    count_post += line.Count;
                }
                #endregion
                //------------------------------------------------------------------------
                //gold hour
                #region gold hour
                foreach (var line in post_list.GroupBy(info => info.create_time.Hour)
                         .Select(group => new
                {
                    Metric = group.Key,
                    Count = group.Count()
                })
                         .OrderBy(x => x.Metric))
                {
                    if (line.Count > max_post)
                    {
                        max_post  = line.Count;
                        gold_hour = (line.Metric + 7) % 24;
                    }
                    if (line.Count < min_post)
                    {
                        min_post    = line.Count;
                        silver_hour = (line.Metric + 7) % 24;
                    }
                }
                #endregion
                //------------------------------------------------------------------------
                //gold hour for comment
                #region gold hour
                var list = v_list_dat.GroupBy(info => info.Hour)
                           .Select(group => new
                {
                    Metric = group.Key,
                    Count  = group.Count()
                })
                           .OrderBy(x => x.Metric);
                foreach (var line in list)
                {
                    if (line.Count > max_comment)
                    {
                        max_comment       = line.Count;
                        gold_hour_comment = (line.Metric + 7) % 24;
                    }
                }
                #endregion
                //------------------------------------------------------------------------
                #region Print Result
                if (count_post == 0)
                {
                    m_lbl_post_per_day.Text = "0";
                }
                else
                {
                    m_lbl_post_per_day.Text = string.Format("{0:0.00}", count_post / count_date);
                }

                if (count_like == 0)
                {
                    m_lbl_like_per_post.Text = "0";
                }
                else
                {
                    m_lbl_like_per_post.Text = string.Format("{0:0.00}", count_like / count_post);
                }

                if (count_comment == 0)
                {
                    m_lbl_comment_per_post.Text = "0";
                }
                else
                {
                    m_lbl_comment_per_post.Text = string.Format("{0:0.00}", count_comment / count_post);
                }
                m_lbl_gold_hour.Text        = "Từ " + gold_hour.ToString() + "h đến " + (gold_hour + 1).ToString() + "h";
                m_lbl_silver.Text           = "Từ " + silver_hour.ToString() + "h đến " + (silver_hour + 1).ToString() + "h";
                m_lbl_gold_hour_action.Text = "Từ " + gold_hour_comment.ToString() + "h đến " + (gold_hour_comment + 1).ToString() + "h";
                #endregion
                m_groupbox.Visible = true;
            }
            catch (Exception v_e)
            {
                MessageBox.Show("Có tý tẹo vấn đề. Bạn chụp ảnh và gửi để chúng tôi hỗ trợ nhé!" + v_e.ToString());
            }
        }