http_interval.py 4.82 KB
Newer Older
1 2 3
'''
Author: your name
Date: 2021-07-22 19:01:41
4
LastEditTime: 2021-07-24 09:48:09
5 6 7 8 9
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\tests\http_interval.py
'''
import json
wanli's avatar
wanli committed
10
import time
11 12
import random
import requests
wanli's avatar
wanli committed
13
from threading import Timer, Thread
14

wanli's avatar
wanli committed
15 16

def send_request(imei):
17
    payload = {
wanli's avatar
wanli committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        "system": {"free_size": 1769792, "free_space_size": 5156864, "used_space_size": 1134592},
        "lvgl": {"total_size": 0, "free_cnt": 0, "free_size": 0, "free_biggest_size": 0, "used_cnt": 0, "used_pct": 0, "frag_pct": 0},
        "evm": {"heap_total_size": 2097152, "heap_used_size": 575072, "heap_map_size": 8192, "stack_total_size": 102400, "stack_used_size": 1312},
        "image": [
            {"uri": "evue_launcher", "length": 13515, "png_total_count": 0,
                "png_uncompressed_size": 0, "png_file_size": 0},
            {"uri": "kdgs_1_startup", "length": 3666, "png_total_count": 0,
                "png_uncompressed_size": 0, "png_file_size": 0},
            {"uri": "kdgs_1_index", "length": 5482, "png_total_count": 0,
                "png_uncompressed_size": 0, "png_file_size": 0},
            {"uri": "kdgs_1_story", "length": 5509, "png_total_count": 0,
                "png_uncompressed_size": 0, "png_file_size": 0},
            {"uri": "kdgs_1_storyList", "length": 9196, "png_total_count": 0,
                "png_uncompressed_size": 0, "png_file_size": 0},
            {"uri": "kdgs_1_storyPlay", "length": 25791, "png_total_count": 6, "png_uncompressed_size": 319376, "png_file_size": 10770, "png_detail": [
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_playBackground.png",
                    "filesize": 7774,
                    "uncompressed_size": 259200,
                    "ratio": 33.341908
                },
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_playLb.png",
                    "filesize": 482,
                    "uncompressed_size": 12544,
                    "ratio": 26.024897
                },
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_playNLike.png",
                    "filesize": 1094,
                    "uncompressed_size": 12544,
                    "ratio": 11.466179
                },
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_playYl.png",
                    "filesize": 745,
                    "uncompressed_size": 12544,
                    "ratio": 16.837584
                },
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_playNext.png",
                    "filesize": 484,
                    "uncompressed_size": 12544,
                    "ratio": 25.917355
                },
                {
                    "uri": "C:/../../test/watch_appstore/kdgs_1_play_bs.png",
                    "filesize": 191,
                    "uncompressed_size": 10000,
                    "ratio": 52.356022
                }
            ]}
70
        ],
wanli's avatar
wanli committed
71
        "imei": imei, "datetime": {"second": 55, "minute": 48, "hour": 15, "day": 21, "month": 7, "year": 2021, "weekday": 3}
72 73
    }

wanli's avatar
wanli committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    while True:
        for item in payload.get("image"):
            item.update({
                'length': 0,
                'png_total_count': 0,
                'png_uncompressed_size': 0,
                'png_file_size': 0
            })

        rand_index = random.randint(0, len(payload.get("image")))
        if rand_index < len(payload.get("image")):
            print("------------------------------>")
        else:
            rand_index = rand_index - 1
            print("rand_index ==>", rand_index)

        payload.get("image")[rand_index].update({
            'length': random.randint(0, 10000),
            'png_total_count': random.randint(0, 10000),
            'png_uncompressed_size': random.randint(100, 100000),
            'png_file_size': random.randint(0, 10000)
95 96
        })

wanli's avatar
wanli committed
97 98 99 100 101
        r = requests.post(
            "http://localhost:3000/api/v1/evm_store/monitor", data=json.dumps(payload))

        print(r.status_code)
        print(r.json())
102

wanli's avatar
wanli committed
103
        time.sleep(3)
104 105


wanli's avatar
wanli committed
106 107 108 109 110 111 112 113 114 115 116 117 118
class myThread(Thread):
    def __init__(self, threadID, name, counter, imei):
        Thread.__init__(self)
        self.threadID = threadID
        self.name = name
        self.counter = counter
        self.imei = imei

    def run(self):
        print("开始线程:" + self.name)
        print(self.counter, self.imei)
        send_request(self.imei)
        print("退出线程:" + self.name)
119 120 121


if __name__ == "__main__":
wanli's avatar
wanli committed
122 123 124 125 126 127 128 129 130 131 132 133
    # send_request()

    # 创建新线程
    thread1 = myThread(1, "Thread-1", 1, "352099001761481")
    thread2 = myThread(2, "Thread-2", 2, "866866040000447")

    # 开启新线程
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()
    print("退出主线程")