先总结一部分吧,边总结边改错
安装pip install apscheduler
from apscheduler.schedulers.blocking import BlockingScheduler
#创建调度器
a=BlockingScheduler()
#定义定时任务
def my_job():
pass
#向调度器添加定时任务,将参数传给定时函数
a.add_job(my_job,'date',args=[100,'python'])
#启动定时任务调度器工作
a.start()#阻塞主进程
调度器BackgroudScheduler:
执行器executors:
使用方法:
from apscheduler.executors.pool import ThreadPoolExecutor
ThreadPoolExecutor(max_workers)
ThreadPoolExecutor(20) # 最多20个线程同时执行
from apscheduler.executors.pool import ProcessPoolExecutor
ProcessPoolExecutor(max_workers)
ProcessPoolExecutor(5) # 最多5个进程同时执行
executors = {
'default': ThreadPoolExecutor(20)
}
scheduler = BackgroundScheduler(executors=executors)
触发器Trigger:
date 在特定的时间日期执行
from datetime import date
# 在2100年11月6日00:00:00执行
sched.add_job(my_job, 'date', run_date=date(2100, 11, 6))
# 在2100年11月6日16:30:05
sched.add_job(my_job, 'date', run_date=datetime(2100, 11, 6, 16, 30, 5))
sched.add_job(my_job, 'date', run_date='2100-11-06 16:30:05')
# 立即执行
sched.add_job(my_job, 'date')
sched.start()
interval 经过指定的时间间隔执行
weeks (int) – number of weeks to wait
days (int) – number of days to wait
hours (int) – number of hours to wait
minutes (int) – number of minutes to wait
seconds (int) – number of seconds to wait
start_date (datetime|str) – starting point for the interval calculation
end_date (datetime|str) – latest possible date/time to trigger on
timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations
from datetime import datetime
# 每两小时执行一次
sched.add_job(job_function, 'interval', hours=2)
# 在2100年10月10日09:30:00 到2104年6月15日的时间内,每两小时执行一次
sched.add_job(job_function, 'interval', hours=2, start_date='2100-10-10 09:30:00', end_date='2104-06-15 11:00:00')
cron 按指定的周期执行
- year (int|str) – 4-digit year
- month (int|str) – month (1-12)
- day (int|str) – day of the (1-31)
- week (int|str) – ISO week (1-53)
- day_of_week (int|str) – number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun)
- hour (int|str) – hour (0-23)
- minute (int|str) – minute (0-59)
- second (int|str) – second (0-59)
- start_date (datetime|str) – earliest possible date/time to trigger on (inclusive)
- end_date (datetime|str) – latest possible date/time to trigger on (inclusive)
- timezone (datetime.tzinfo|str) – time zone to use for the date/time calculations (defaults to scheduler timezone)
# 在6、7、8、11、12月的第三个周五的00:00, 01:00, 02:00和03:00 执行
sched.add_job(job_function, 'cron', month='6-8,11-12', day='3rd fri', hour='0-3')
# 在2104年5月30日前的周一到周五的5:30执行
sched.add_job(job_function, 'cron', day_of_week='mon-fri', hour=5, minute=30, end_date='2104-05-30')
使用:
scheduler.add_job(myfunc, 'interval', minutes=2, id='my_job_id') # 添加任务
scheduler.remove_job('my_job_id') # 删除任务
scheduler.pause_job('my_job_id') # 暂定任务
scheduler.resume_job('my_job_id') # 恢复任务
#调整任务调度周期
job.modify(max_instances=6, name='name')
scheduler.reschedule_job('my_job_id', trigger='cron', minute='*/5')
#停止APScheduler运行
scheduler.shutdown()
安装:
编写接口描述文件.proto:
使用:
HTTP/1.1:
HTTP/2 还未完全推广
WebSocket 80端口(TLS时443端口):
Relational DB -> Databases 数据库 -> Tables 表 -> Rows 行 -> Columns 列
Elasticsearch -> Indices 索引库 -> Types 类型 -> Documents 文档 -> Fields 字段/属性
集群:
curl
curl -x请求方式 请求网址 -h 请求头 -d请求体
curl -X GET 请求网址/pettr
安装IK中文分析器elasticsearch-analysis-ik
创库:
# 创建blogs名字的库
curl -X PUT 127.0.0.1:9200/blogs -H 'Content-Type:application/json' -d '
{
"settings" : {
"number_of_shards" : 3, 主分片数量
"number_of_replicas" : 1 每个主分片对应的复制分片的数量
}
}'
删库 DELETE /库
修改 PUT /库 按照创库方式重写
**表(types)映射:**一个库一张表 5.*版本
创表:
curl -X PUT 127.0.0.1:9200/库/_mappong/表名 -H 'Content-Type:application/json' -d ‘{
"all":{
"analyzer":"ik_max_word"
},
"properties":{
"字段名":{
"type":"long",
"analyzer":"ik_max_word" #指明中文分析器
"include_in_all":"false"#是否可以被all索引查出
“boost”:设置权重
}
}
}’
查表:
改表:
新增字段:
不允许修改老子段。只能新建库,表
允许数据迁移到新表
curl -X POST 127.0.0.1:9200/_reindex -H 'Content-Type:application/json' -d '{
"soure":{
“index”:老库名字
}
},
"dest":{
“index”:新库名字
}
'
删除旧库改新库的名字
curl -X PUT 127.0.0.1:9200/新库名/_lias/要改的名字
文档(数据):
增:
curl -X PUT 127.0.0.1:9200/库名/表名/增加数据的指定id(可以不指定) -H 'Content-Type:application/json' -d “{数据}”
查:
curl -X GTT 127.0.0.1:9200/库名/表名/数据id
数据导入:
从mysql导入
tar -zxvf mysql-connector-java-8.0.13.tar.gz
搜索查询:
Elasticsearch是如何实现Master选举的?
释放了GIL锁
z.T z.transpose()矩阵转置 z.reshape()设置矩阵
z.loadtxt。(文件名,切割字符delimiter,展示类型dtype,unpack是否转置)
z.arange(定义数组)
nan =不是数字 numpy.nan赋值 inf无穷
z.astype()转换类型
z.sum(,axis=0/行 1/列) 总和
z.mean 均值 median 中值 max min ptp极值 std标准差
np.zeros()全为0 np.ones
np.hastack(数据,添加列,水平拼接)
np.vstack((竖直拼接))
np.eye()创建方正
np.argmax/min(数据,axis=0)获取当前行/列最大/小值的位置
np.random.randit(范围,范围(行,列))整数.uniform小数 .seed()随机一样
a = b.copy() 互不影响,直接复制会影响
索引、切片**:
nan&±inf:
Series (一维,带标签的数组):
len
、list什么的DataFrame( 二维,Series 的容器):
pd.DataFrame(np.arange(12).reshape(3,4),index=list(“abc”),columns=list(‘wxyz’))
t[:][字段]
得到某一行前几个常用统计方法:
分组聚合:
索引:t.index() t.index=重新赋值索引
时间序列:
assert(断言)
单元测试模块unittest:
导入main中的执行路径,并根据当前文件修改路径
import unittest #对assert进行了封装
import craete_app
import 配置中的测试类
class TestClass(unittest.TestCase):
#首先执行,测试的准备工作
def setUp(self):
pass
#利用python提供http请求模块urllib2、request发送请求,执行前必须开启服务器。
#flask框架提供了单元测试客户端对象,发送http请求,这种情况不需要运行flask服务器。a = app.test_client(),a.get()就会发送get请求
#导入craete_app 封装一个test模式下的配置
app = craete_app(集成测试类)
self.client = app.test_client()
#会在测试代码完成后执行,测试后的扫尾工作。例:清理测试添加数据库的数据
def tearDown(self):
pass
#自己的测试代码,函数名必须test_开头
def test_xxxxx(self):
pass
resp = self.client.get(‘直接写路径’)
#resp是响应对象,resp.data是原始响应体数据,resp.atatus_code状态码
self.assertEqual(resp.atatus_code, 200) #检测等值
#解析json字符串 导入json
resp_dict = json.loads(resp.data)
self.assertIn(数据的键,数据集) #数据体是否存在字段
if __name__ == '__main__':
unittest.main()
一般在app同级目录(工程目录)下建立test文件夹:
python实现的进程管理工具,只要需要自动维护进程管理都可以使用,不局限于web开发。
可以帮助我们看护进程,若进程以外退出supervisor可以自动重启
from sklearn.feature_extraction import DictVectorizer
创建 DictVectorizer(sparse=false就是矩阵)对象 使用.fit_transform(字典列表) one-hot编码
plt.figure(figsize=(20, 8), dpi=80) #创建画布
plt.plot(x, y_shanghai) #生成图像
x_ticks_label = ["11点{}分".format(i) for i in x] #构造x刻度
y_ticks = range(40) #构造Y刻度
# 修改x,y轴坐标的刻度显示
plt.xticks(x[::5], x_ticks_label[::5])
plt.yticks(y_ticks[::5])
plt.grid(True, linestyle='--', alpha=0.5) #添加网格
#添加x,y轴名字以及标题信息
plt.xlabel("时间")
plt.ylabel("温度")
plt.title("中午11点0分到12点之间的温度变化图示", fontsize=20)
plt.savefig("./test.png") #保存图像
plt.show() #显示图像
多次绘图是只需要在pt.plot就可以(同一个图)
plt.plot(x, y_beijing, color='r', linestyle='--') #加lable才会显示图例
plt.legend(loc="best") #显示图例
#创建多个画布可用下标使用,通过添加set_方法设置不同画布
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(20, 8), dpi=100)
折线图 pt.plot 散点图pt.scatter 柱状图plt.bar(x, width(图形宽度), align='center'(对齐方式), **kwargs(颜色))
直方图 matplotlib.pyplot.hist(x, bins=None(组距))
饼图 plt.pie(x, labels=(每部分名称),autopct=(占比显示指定%1.2f%%),colors)
图形颜色:
颜色字符 | 风格字符 |
---|---|
r 红色 | - 实线 |
g 绿色 | - - 虚线 |
b 蓝色 | -. 点划线 |
w 白色 | : 点虚线 |
c 青色 | ’ ’ 留空、空格 |
m 洋红 | |
y 黄色 | |
k 黑色 |
配置中文:
解决方案一:
下载中文字体(黑体,看准系统版本)
步骤一:下载 SimHei 字体(或者其他的支持中文显示的字体也行)
步骤二:安装字体
linux下:拷贝字体到 usr/share/fonts 下:
sudo cp ~/SimHei.ttf /usr/share/fonts/SimHei.ttf
windows和mac下:双击安装
步骤三:删除~/.matplotlib中的缓存文件
cd ~/.matplotlib
rm -r *
步骤四:修改配置文件matplotlibrc
vi ~/.matplotlib/matplotlibrc
将文件内容修改为:
font.family : sans-serif
font.sans-serif : SimHei
axes.unicode_minus : False
解决方案二:
from pylab import mpl
# 设置显示中文字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]
# 设置正常显示符号
mpl.rcParams["axes.unicode_minus"] = False