Esempio n. 1
0
        private void sort_workers(bool allow_change_coin = true, bool skip_check = false)
        {
            //unfreeze
            DateTime dt_now = DateTime.Now;

            foreach (var itt in enabled_workers)
            {
                if (itt.Value.stopped_before != DateTime.MinValue)
                {
                    if (itt.Value.stopped_before < dt_now)
                    {
                        itt.Value.stopped_before = DateTime.MinValue;
                    }
                }
            }

            var lnq = from it in enabled_workers
                      orderby it.Value.cant_run, it.Value.stopped_before, it.Value.get_diff()
            select it;

            List <int> s = new List <int>();

            foreach (var itt in lnq)
            {
                s.Add(itt.Key);
            }

            if (!s.SequenceEqual(currnet_sort))
            {
                //check threshold delta and min_running time
                if (allow_change_coin && !skip_check)
                {
                    double   current_d     = 0;
                    double   f_d           = 0;
                    int      test_next_id  = 0;
                    int      min_running   = 0;
                    DateTime start_running = DateTime.MinValue;
                    bool     check_ok      = true;
                    for (int i = 0; i < currnet_sort.Count; ++i)
                    {
                        int id = currnet_sort[i];
                        work_item_struct it = enabled_workers[id];
                        if (i == 0)
                        {
                            f_d          = it.get_diff();
                            test_next_id = id;
                        }
                        if (id == current_id_running)
                        {
                            current_d     = it.get_diff();
                            min_running   = it.min_running;
                            start_running = it.start_running;

                            if (it.cant_run || it.stopped_before != DateTime.MinValue)
                            {
                                check_ok = false;
                            }
                        }
                    }
                    if (check_ok)
                    {
                        if (test_next_id != current_id_running)
                        {
                            if (current_d - f_d < threshold_switch_delta)
                            {
                                refresh_workers_display();
                                return;
                            }
                        }
                        if (min_running != 0 && (int)((DateTime.Now - start_running).TotalMinutes) < min_running)
                        {
                            refresh_workers_display();
                            return;
                        }
                    }
                }

                bool change_coin = false;

                currnet_sort = s;
                panel1.Controls.Clear();
                for (int i = 0; i < currnet_sort.Count; ++i)
                {
                    int id = currnet_sort[i];

                    work_item_struct it = enabled_workers[id];

                    if (i == 0)
                    {
                        it.is_running = true;
                        if (it.id != current_id_running)
                        {
                            change_coin        = true;
                            current_id_running = it.id;
                        }
                    }
                    else
                    {
                        it.is_running = false;
                    }

                    work_item item = new work_item();
                    item.init(ref it);
                    item.Left = 3;
                    item.Top  = (panel1.Controls.Count * (item.Height + 3)) + 3;
                    panel1.Controls.Add(item);
                }

                if (change_coin && allow_change_coin)
                {
                    refresh_workers_display();

                    richTextBox2.AppendText("\n[strategy] ", Color.Green);
                    richTextBox2.AppendText("Changing coin");
                    is_running.Value = false;
                    autostart_flag   = true;
                }
            }
        }
Esempio n. 2
0
        public void refresh()
        {
            pictureBox1.Image = Image.FromFile(dlls.get_coin_image(data.coin));
            if (data.is_running)
            {
                pictureBox2.Image = Properties.Resources.start;
            }
            else
            {
                pictureBox2.Image = Properties.Resources.stop;
            }

            switch (data.get_coin_stat_state())
            {
            case work_item_struct.coin_stat_state.manual: pictureBox3.Image = Properties.Resources.gray; break;

            case work_item_struct.coin_stat_state.stat_ok: pictureBox3.Image = Properties.Resources.green; break;

            case work_item_struct.coin_stat_state.stat_error: pictureBox3.Image = Properties.Resources.red; break;
            }

            label1.Text = data.coin;
            label2.Text = data.exchange_name;
            label3.Text = data.pool_name;
            label4.Text = data.miner;
            if (data.abs_diff == -1)
            {
                label7.Text = "-";
            }
            else
            {
                label7.Text = ((int)data.abs_diff).ToString();
            }
            string diff_rel = data.get_diff().ToString();

            if (diff_rel.Length > 3)
            {
                diff_rel = diff_rel.Substring(0, 3);
            }
            label9.Text  = diff_rel;
            label13.Text = data.min_running.ToString();
            if (data.min_running != 0 && data.is_running && data.start_running != DateTime.MinValue)
            {
                int running_min = data.min_running - (int)(DateTime.Now - data.start_running).TotalMinutes;
                if (running_min < 0)
                {
                    running_min = 0;
                }
                label15.Text = running_min.ToString();
            }
            else
            {
                label15.Text = "-";
            }

            DateTime curr_date = DateTime.Now;

            db.select("select count(*) from times where id_pool = " + data.id + " and dat >='" + curr_date.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss") + "'; ", new db_sqlite.dell((System.Data.Common.DbDataRecord record) =>
            {
                int m   = baseFunc.base_func.ParseInt32(record[0]);
                int min = m % 60;
                int h   = (m - min) / 60;

                string min_str = min.ToString();
                string h_str   = h.ToString();
                if (min_str.Length == 1)
                {
                    min_str = "0" + min_str;
                }
                if (h_str.Length == 1)
                {
                    h_str = "0" + h_str;
                }

                int perc = (int)((double)(m * 100) / 1440.0);

                label11.Text = h_str + ":" + min_str + " (" + perc + "%)";
                return(true);
            }));

            if (data.cant_run)
            {
                pictureBox2.Image = Properties.Resources.warn;
            }
            else if (data.stopped_before != DateTime.MinValue)
            {
                pictureBox2.Image = Properties.Resources.warn;
            }
        }