返回列表 发帖
本帖最后由 bbaa 于 2017-7-23 14:21 编辑

回复 134# 523066680


    勉强看懂...一点点.............
曲线图AJAX更新已经发布
点击打开

前端使用类库
chart.js
jquery.....
后端用https://git.oschina.net/kenvix/Tieba-Cloud-Sign的数据库操作类[我太懒了.....][之前还用文件存储来着?]
信息收集
/* Model:曲线图变化速度信息收集模块 Start */
$dataqx=json_decode(str_replace("\\\u","\u",option::get("bbaa_math_text")),true);
$json=Json_decode(getsql(),true);
/* 如果在主项中已经没有这个用户,在数据中删除掉 */
foreach($dataqx as $zh=>$va) {
if(empty($json["Username"][$zh])) {
Unset($dataqx[$zh]);
}
}
/* 如果在主项中已经没有这个用户,在数据中删除掉 End*/
//$times=time()-(int)$change["change"]["fminute"]["last"]["Timestamp"];
foreach ($change["change"]["minute"]["done"]["user"] as $key=>$value) {
If ($qst) {
//unset($dataqx[$key]["Timestamp"]);
if((int)Count($dataqx[$key]["data"])<12) {
$dataqx[$key]["data"][Count($dataqx[$key]["data"])]=$value;
} else {
/* 对于data12的一个处理 {*/
$temp=Array(); //对foreach的处理机制做出应对
foreach ($dataqx[$key]["data"] as $keyt=>$val) {
if ((int)$keyt>0&&(int)$keyt<12) {
$temp[$key]["data"][Count($temp[$key]["data"])]=$val;
}
}
Unset($dataqx[$key]["data"]);
$dataqx[$key]["data"]=$temp[$key]["data"]; //合并
Unset($temp);
/* 对于data12的一个处理 }*/
$dataqx[$key]["data"][Count($dataqx[$key]["data"])]=$value;
unset ($count);
}
}
}
/* Model:曲线图变化速度信息收集模块 End *COPY
case "getlinedata":
$json=Json_decode(getsql(),true);
$Timestamp=$change_tmp["change"]["minute"]["last"]["Timestamp"];
$if_date=date("H:i",$Timestamp);
if($if_date==$_POST["Timestamp"]) {die(json_encode(array("Code"=>400)));}
unset($change_tmp);
$change=json_decode(str_replace("\\\u","\u",option::get("bbaa_math_text")),true);
$tmp=Array();
foreach($_POST["list"] as $value) {
$tmp[$value]=$change[$value]["data"][count($change[$value]["data"])-1];
}
die(json_encode(array("Code"=>200,"data"=>$tmp,"Timestamp"=>$if_date)));
unset($tmp);
break;COPY
后端更新频率一分钟一次
前端get频率10秒一次

点击打开
外链图片展示
因alpha(透明)通道等原因背景为黑
2

评分人数

TOP

朋友推荐我听这首歌
拿出来祸害人类
http://music.163.com/#/m/song?id=4466775&userid=379014753

TOP

我在这个帖子下看到各种语言写的程序,被夸到飞起来,那个6啊。
坐等新的突破
[url=][/url]

TOP

多线程,实测速度能稳定在 20/min 以上(由网络环境决定)
Java 代码
import com.google.gson.Gson;
import okhttp3.*;
import java.io.IOException;
public class Main {
    private static final OkHttpClient client = new OkHttpClient();
    private volatile static int calls = 0;
    private static int min = -1;
    private static int max = 10001;
    private static String tokens = null;
    private static boolean finished = false;
    private static int times = 0;
    static {
        client.dispatcher().setMaxRequests(Integer.MAX_VALUE);
        client.dispatcher().setMaxRequestsPerHost(Integer.MAX_VALUE);
    }
    public static void main(String[] args) {
        int next;
        int add;
        long start = System.nanoTime();
        while (true) {
            if (calls != 0) continue;
            if (finished) {
                System.out.println(String.format("%d 次 %fs", times, (System.nanoTime() - start) / 1000000000d));
                start = System.nanoTime();
                times = 0;
                finished = false;
            }
            if (max - min < 10) {
                for (int i = min + 1; i < max; i++) {
                    guessAsync(i);
                }
                continue;
            }
            next = min;
            add = (max - min) / 4;
            for (int i = 0; i < 3; i++) {
                guessAsync(next += add);
            }
        }
    }
    private static void guessAsync(int num) {
        FormBody body = new FormBody.Builder()
                .add("send", "Answer")
                .add("math", String.valueOf(num))
                .add("username", "Scallop")
                .build();
        Request request = new Request.Builder().url("http://bbaass.tk/math/").post(body).build();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                calls--;
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                synchronized (client) {
                    try {
                        if (finished) {
                            response.close();
                            calls--;
                            return;
                        }
                        if (!response.isSuccessful()) {
                            response.close();
                            System.out.println("---故障---");
                            calls--;
                            return;
                        }
                        BBAAResponse result = new Gson().fromJson(response.body().string(), BBAAResponse.class);
                        response.close();
                        String re = result.re;
                        boolean reset = !result.tokens.equals(tokens) && !re.equals("=");
                        if (reset) {
                            if (!result.winer.equals("Scallop")) {
                                System.out.println(String.format("---重置 by %s---", result.winer));
                            }
                            tokens = result.tokens;
                        }
                        switch (result.re) {
                            case "<":
                                if (min < num) min = num;
                                if (reset) max = 10001;
                                break;
                            case "=":
                                min = -1;
                                max = 10001;
                                finished = true;
                                break;
                            case ">":
                                if (max > num) max = num;
                                if (reset) min = -1;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    calls--;
                }
            }
        });
        calls++;
        times++;
    }
    private static class BBAAResponse {
        int code;
        String re;
        String tokens;
        String winer;
    }
}COPY

TOP

本帖最后由 523066680 于 2017-7-29 08:28 编辑



截图中 adad 的速度是S发布的代码在另一台电脑上运行的结果(当时vic3的程序暂停了)


情况就是这么个情况。

          评分君好像很激动……
                       |
1

评分人数

    • codegay: 继续晒数据啊。技术 + 1
[url=][/url]

TOP

回复 140# 523066680


    那么C语言版能跑出惊人的数据?
去学去写去用才有进步。安装python3代码存为xx.py 双击运行或右键用IDLE打开按F5运行

TOP

本帖最后由 523066680 于 2018-12-25 21:05 编辑

回复 141# codegay

    那个时候最大的问题是我们这一边的代码几乎都没有加 keep_alive,导致提交速度慢了好多倍。
对方提供的java程序跑起来速度翻倍怎么想都有点夸张,特别是看到源码后发现他们的算法也还有优化空间(bulls and cows那个游戏),
当时不懂网络就错误地怀疑是程序性能啦(java的网络库也确实快)。

到了数独游戏,C语言+DLX算法是真的快。
[url=][/url]

TOP

返回列表