小编one*_*ser的帖子

python pandas:如何计算导数/渐变

鉴于我有以下两个向量:

In [99]: time_index
Out[99]: 
[1484942413,
 1484942712,
 1484943012,
 1484943312,
 1484943612,
 1484943912,
 1484944212,
 1484944511,
 1484944811,
 1484945110]

In [100]: bytes_in
Out[100]: 
[1293981210388,
 1293981379944,
 1293981549960,
 1293981720866,
 1293981890968,
 1293982062261,
 1293982227492,
 1293982391244,
 1293982556526,
 1293982722320]
Run Code Online (Sandbox Code Playgroud)

其中bytes_in是仅增量计数器,time_index是unix时间戳(epoch)的列表.

目标:我想要计算的是比特率.

这意味着我将构建一个数据框

In [101]: timeline = pandas.to_datetime(time_index, unit="s")

In [102]: recv = pandas.Series(bytes_in, timeline).resample("300S").mean().ffill().apply(lambda i: i*8)

In [103]: recv
Out[103]: 
2017-01-20 20:00:00    10351849683104
2017-01-20 20:05:00    10351851039552
2017-01-20 20:10:00    10351852399680
2017-01-20 20:15:00    10351853766928
2017-01-20 20:20:00    10351855127744
2017-01-20 20:25:00    10351856498088
2017-01-20 20:30:00    10351857819936
2017-01-20 20:35:00    10351859129952
2017-01-20 …
Run Code Online (Sandbox Code Playgroud)

python data-analysis pandas

14
推荐指数
1
解决办法
2万
查看次数

aiohttp:如何从requests.get中检索aiohttp服务器中的数据(正文)

你能否就以下事项提出建议?

localhost:8900那里有aiohttp服务器运行

当我从python做一个请求(使用python2模块请求)

requests.get("http://127.0.01:8900/api/bgp/show-route",
             data={'topo':"switzerland",
                   'pop':"zrh",
                   'prefix':"1.1.1.1/32"})
Run Code Online (Sandbox Code Playgroud)

并且在aiohttp服务器中定义了一个路由

app.router.add_route("GET", "/api/bgp/show-route", api_bgp_show_route)
Run Code Online (Sandbox Code Playgroud)

正在被处理的像

def api_bgp_show_route(request):
    pass
Run Code Online (Sandbox Code Playgroud)

问题是:如何在服务器端检索请求的数据部分?含义{'topo':"switzerland", 'pop':"zrh", 'prefix':"1.1.1.1/32"}

python rest python-3.x aiohttp

7
推荐指数
3
解决办法
8909
查看次数

Elasticsearch:HOW-TO删除(群集)设置

我当前的光泽配置设置如下所示:

{
  "persistent": {
    "indices": {
      "store": {
        "throttle": {
          "type": "none",
          "max_bytes_per_sec": "150mb"
        }
      }
    }
  },
  "transient": {}
}
Run Code Online (Sandbox Code Playgroud)

我想知道如何删除设置的"max_bytes_per_sec"部分.

你能告诉我这个吗?

rest settings elasticsearch

6
推荐指数
3
解决办法
8222
查看次数

如何:使用python-ldap进行LDAP绑定+身份验证

您能否建议以下故障排除方法;我试图绑定到ldap服务器,但是徒劳无功,

openssl s_client -CApath /etc/pki/ca-trust/source/anchors/ -connect ...:636
Run Code Online (Sandbox Code Playgroud)

成功:

 Verify return code: 0 (ok)
Run Code Online (Sandbox Code Playgroud)

那是从系统方面来看的,但是当我尝试通过python-ldap模块进行绑定时:

In [1]: import ldap

In [2]: l = ldap.initialize('ldaps://...:636')

In [3]:  ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_ALLOW)

In [4]: l.set_option(ldap.OPT_X_TLS_CACERTFILE,"/etc/pki/ca-trust/source/anchors/cacert.pem")

In [5]: l.set_option(ldap.OPT_X_TLS_NEWCTX,0)

In [6]: l.simple_bind_s("...", "...")
---------------------------------------------------------------------------
SERVER_DOWN                               Traceback (most recent call last)
<ipython-input-6-a59dae8ba541> in <module>()
----> 1 l.simple_bind_s("...", "...")

/usr/lib64/python2.7/site-packages/ldap/ldapobject.pyc in simple_bind_s(self, who, cred, serverctrls, clientctrls)
    205     simple_bind_s([who='' [,cred='']]) -> None
    206     """
--> 207     msgid = self.simple_bind(who,cred,serverctrls,clientctrls)
    208     resp_type, resp_data, resp_msgid, resp_ctrls = self.result3(msgid,all=1,timeout=self.timeout)
    209     return resp_type, resp_data, …
Run Code Online (Sandbox Code Playgroud)

python ssl ldap certificate python-ldap

5
推荐指数
1
解决办法
1万
查看次数

rpy2:如何获取调用 R 函数的返回值

我想R在以下位置使用以下脚本Python

> library(bfast)
> apple <- read.csv("/Users/nskalis/Downloads/R/apple.csv", sep = ";", header=TRUE)
> data = apple
# data$in_bps: is vector of double numbers
> data.ts <- ts(data$in_bps, frequency=1)
> data.fit <- bfast(data.ts, h=0.1, season="none", max.iter=1)
> data.fit$output[[1]]$Tt
> data.fit$output[[1]]$Vt.bp
> data.fit$output[[1]]$ci.Vt
> data.fit$output[[1]]$ci.Vt$confint
Run Code Online (Sandbox Code Playgroud)

因此我正在使用rpy2并做了以下操作:

from rpy2.robjects.packages import importr
import rpy2.robjects as robjects
importr("bfast")
data = range(1,100)
data = robjects.FloatVector(data)
data = robjects.r.ts(data, frequency=1)
x = robjects.r.bfast(data, h=0.1, season="none", max_iter=1)
Run Code Online (Sandbox Code Playgroud)

结果变量x等于

In [42]: x …
Run Code Online (Sandbox Code Playgroud)

python r rpy2

5
推荐指数
1
解决办法
2035
查看次数

有没有办法使用Python后端服务器检索客户端IP地址

有问题的设置如下所示:

我的网络应用程序使用和工作类fastapi实现和部署,位于具有IP地址的同一主机上的代理后面(以及其他远程设备后面,例如VPN集中器等)gunicornuvicornnginx172.31.x.x

nginx配置如下:

location / {
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;
    set_real_ip_from 172.31.x.x/32;  # well-known vpn concentrator

    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_redirect off;
    proxy_pass http://172.31.x.x:5045;
Run Code Online (Sandbox Code Playgroud)

gunicorn配置如下:

OPTIONS="--bind 127.0.0.1:5045 --bind 172.31.x.x:5045 --forwarded-allow-ips=127.0.0.1,172.31.x.x --workers 1 --worker-class uvicorn.workers.Uv
icornWorker --log-config config/logging.conf"
Run Code Online (Sandbox Code Playgroud)

fastapi使用starlette.requests.Request对象(名为request)时,request.client.host打印托管 Web 应用程序的服务器的接口 IP 地址(即172.31.x.x

request.headers["x-real-ip"], request.headers["x-forwarded-for"]两者都打印我的代理之前设备的 IP 地址,这是我公司中众所周知的防火墙设备。

我想问的是:

  1. 是否可以打印整个X-Forwarded-ForHTTP 标头来查看中间代理服务?
  2. 如何检索最终用户的真实客户端 IP 地址(基本上覆盖众所周知的白名单 IP 地址)?

python-3.x gunicorn starlette fastapi uvicorn

5
推荐指数
0
解决办法
3162
查看次数

Ansible:如何做数学并得到一个整数?

如果我们假设这ansible_memtotal_mb是一个奇数

- debug: msg="{{ ansible_memtotal_mb }}"
Run Code Online (Sandbox Code Playgroud)

如何除以ansible_memtotal_mb2,并将结果转换为整数:

- debug: msg="{{ ansible_memtotal_mb * 0.5 | int }}"
Run Code Online (Sandbox Code Playgroud)

显然后者不起作用,因为(如果我没记错的话) ansible_memtotal_mb * 0.5返回一个字符串并使用int过滤器,结果为0

您能否提一些建议?

python jinja2 ansible

4
推荐指数
1
解决办法
3834
查看次数

AH00534:httpd:配置错误:未加载 MPM

我有一个CentOS Linux release 7.1.1503 (Core)系统,我已经安装了httpd,相应的配置文件是:

#
# This is the main rConfig Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.2/> for detailed information.
# In particular, see
# <URL:http://httpd.apache.org/docs/2.2/mod/directives.html>
# for a discussion of each configuration directive.
#
ServerTokens OS

ServerRoot "/etc/httpd"

PidFile run/httpd.pid

Timeout 60

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 15

<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule> …
Run Code Online (Sandbox Code Playgroud)

apache centos

2
推荐指数
1
解决办法
1万
查看次数

jupyter:没有可用的内核

有人可以告诉我为什么我没有选择python3作为内核的选项吗?

# python3 -m ipykernel install --user
Installed kernelspec python3 in /root/.local/share/jupyter/kernels/python3

# python3 -m pip install ipykernel
Requirement already satisfied: ipykernel in /usr/lib/python3.4/site-packages
Requirement already satisfied: tornado>=4.0 in /usr/lib64/python3.4/site-packages (from ipykernel)
Requirement already satisfied: ipython>=4.0.0 in /usr/lib/python3.4/site-packages (from ipykernel)
Requirement already satisfied: jupyter-client in /usr/lib/python3.4/site-packages (from ipykernel)
Requirement already satisfied: traitlets>=4.1.0 in /usr/lib/python3.4/site-packages (from ipykernel)
Requirement already satisfied: backports_abc>=0.4 in /usr/lib/python3.4/site-packages (from tornado>=4.0->ipykernel)
Requirement already satisfied: pexpect; sys_platform != "win32" in /usr/lib/python3.4/site-packages (from ipython>=4.0.0->ipykernel)
Requirement …
Run Code Online (Sandbox Code Playgroud)

ipython-notebook jupyter jupyter-notebook

2
推荐指数
1
解决办法
1万
查看次数

postgres:如何在.sql文件中执行脚本

在SQLite中你可以做到

sqlite3 i.db < x.sql
Run Code Online (Sandbox Code Playgroud)

where x.sql是一个create table语句,i.db是数据库

PostgreSQL中的等价物是什么?

postgresql

-2
推荐指数
1
解决办法
1059
查看次数