Пример #1
0
        public async void init(string did)
        {
            state = new bool[50];
            for (int i = 0; i < 50; i++)
            {
                state[i] = false;
            }
            var result = await HttpUtil.GetDuties(did);

            if ((bool)result["ok"])
            {
                JArray duties = (JArray)result["duties"];
                JArray counts = (JArray)result["counts"];

                for (var i = 0; i < duties.Count; i++)
                {
                    DutyItem D = new DutyItem();
                    D.cno  = (int)duties[i]["dno"];
                    D.name = (string)duties[i]["name"];
                    long second = (long)duties[i]["time"];
                    D.time = new DateTime(second);
                    D.note = (string)duties[i]["note"];
                    dutyitems.Add(D);
                }
                for (var i = 0; i < counts.Count; i++)
                {
                    CountItem C = new CountItem();
                    C.count = (int)counts[i]["count"];
                    C.name  = (string)counts[i]["name"];
                    C.no    = (int)counts[i]["mno"];
                    countitems.Add(C);
                }
            }
            else
            {
                var md = new MessageDialog("duty models init fail!!").ShowAsync();
                return;
            }
            result = await HttpUtil.GetMembers(App.account);

            if ((bool)result["ok"])
            {
                JArray member = (JArray)result["members"];
                for (var i = 0; i < member.Count; i++)
                {
                    string     mno = (string)member[i]["mno"];
                    MemberItem m   = new MemberItem();
                    m.name = (string)member[i]["name"];
                    long second = (long)member[i]["birth"];
                    m.birth    = new System.DateTime(second);
                    m.pic      = new System.Uri("http://www.sysu7s.cn:3000/api/dormitory//get-member-image/" + App.account + "/" + mno);
                    m.location = (string)member[i]["location"];
                    memberitems.Add(m);
                }
            }
        }
Пример #2
0
        private async void RandomButton_Click(object sender, RoutedEventArgs e)
        {
            //总次数倒数之和
            double TotalCount = 0;
            double random     = 0;

            //概率模型
            double[] pro = new double[ViewModel.countitems.Count];
            for (int i = 0; i < ViewModel.countitems.Count; i++)
            {
                double a = 1.0 / (double)ViewModel.countitems[i].count;
                TotalCount += a;
            }
            for (int i = 0; i < ViewModel.countitems.Count; i++)
            {
                double a = 1.0 / (double)ViewModel.countitems[i].count;
                if (i == 0)
                {
                    pro[i] = a / TotalCount;
                }
                else
                {
                    pro[i] = a / TotalCount + pro[i - 1];
                }
            }
            Random ro = new Random();

            random = ro.NextDouble();
            int no = 0;

            for (int i = 0; i < ViewModel.countitems.Count; i++)
            {
                if (random < pro[i])
                {
                    no = i;
                    break;
                }
            }
            while (ViewModel.state[no] == false)
            {
                ro     = new Random();
                random = ro.NextDouble();
                no     = 0;
                for (int i = 0; i < ViewModel.countitems.Count; i++)
                {
                    if (random < pro[i])
                    {
                        no = i;
                        for (int j = 0; i < ViewModel.state.Length; i++)
                        {
                            ViewModel.state[i] = false;
                        }
                        break;
                    }
                }
            }
            this.pict.Source = new BitmapImage(ViewModel.memberitems[no].pic);
            //(pict.Source as BitmapImage).UriSource = ViewModel.memberitems[no].pic;
            DateTime date   = DateTime.Now;
            string   note   = Note.Text;
            var      result = await HttpUtil.GetMemberNames(App.account); //狗哥把这段改为直接从mem_List拿名字

            string   name = (string)result["names"][no];
            DutyItem D    = new DutyItem(no, name, date, note);

            ViewModel.dutyitems.Add(D);

            await HttpUtil.AddDuty(App.account, no, D);
        }