我用来react-query在同一个 React 组件中进行两个单独的查询。我最初尝试使用两个useQuery钩子:
export default function Component() {
const [barData, setBarData] = useState();
const [lineData, setLineData] = useState();
const { error: errorBar, isLoading: loadingBar } = useData(
"barQuery",
"BAR_TEST_SINGLE",
setBarData
);
const { error: errorLine, isLoading: loadingLine } = useData(
"lineQuery",
"LINE_TEST",
setLineData
);
const isLoading = loadingLine && loadingBar;
const error = errorLine && errorBar;
if (isLoading) return <LoadingSpinner title={title} />;
if (error)
return <InvalidStateAPI description={error.message} title={title} />;
return (
<>
<Line data={lineData} />
<Bar …Run Code Online (Sandbox Code Playgroud) 我按照这篇博文来使用 Docker 创建一个与 AWS Lambda 结合使用的运行时环境。我正在创建一个用于 Python 3.8 的层:
docker run -v "$PWD":/var/task "lambci/lambda:build-python3.8" /bin/sh -c "pip install -r requirements.txt -t python/lib/python3.8/site-packages/; exit"
Run Code Online (Sandbox Code Playgroud)
然后将图层存档为 zip:zip -9 -r mylayer.zip python
到目前为止都是标准的。问题出现在.zip大小上,> 250mb,因此在 Lambda 中产生以下错误:Failed to create layer version: Unzipped size must be smaller than 262144000 bytes。
这是我的requirements.txt:
s3fs
scrapy
pandas
requests
Run Code Online (Sandbox Code Playgroud)
我s3fs之所以将其包括在内,是因为在尝试使用 pandas: 将 parquet 文件保存到 S3 存储桶时出现以下错误[ERROR] ImportError: Install s3fs to access S3。这个问题是包含s3fs大量增加层大小。如果没有s3fs该层,解压缩后的大小 …
我在 Scrapy 中有一个蜘蛛,我想检查瓶颈。我还有一些类进入主 Spider 类。我想使用 cProlifer 检查函数执行时间:
if __name__ == '__main__':
import pstats
import cProfile
from pstats import SortKey
cProfile.run("QuotesSpider(scrapy.Spider)", "output.dat")
with open('output_time.txt', 'w') as f:
p = pstats('output.dat', stream=f)
p.sort_stats('time').print_stats()
with open('output_calls.txt', 'w') as f :
p = pstats('output.dat', stream=f)
p.sort_stats('calls').print_stats()
Run Code Online (Sandbox Code Playgroud)
QuotesSpider(scrapy.Spider)蜘蛛类在哪里。可以理解的是,当使用 运行蜘蛛时scrapy crawl quotes,我收到以下错误:NameError: name 'QuotesSpider' is not defined。
如何正确地将 cProfile 与 Scrapy 集成?由于 Scrapy 的请求是异步的,cProfile 是解决这个问题的最佳方法吗?
我正在开发一个需要坐标映射的项目 - 确定坐标点是否存在于一系列多边形中。映射的数量相当大 - 跨越 100 多个多边形的约 1000 万个坐标。
在继续之前,我已经查看了此处和此处的问题。这个问题并不多余,因为它涉及动态点和静态多边形。
我通过在 200 万个多边形的子集中映射单个坐标来缩小该问题的项目范围。这是我使用的代码:
from shapely.geometry import shape, Point
f = open('path/to/file.geojson', 'r')
data = json.loads(f.read())
point = Point(42.3847, -71.127411)
for feature in data['features']:
polygon = shape(feature['geometry'])
if polygon.contains(point):
print(polygon)
Run Code Online (Sandbox Code Playgroud)
迭代 200 万个多边形(在本例中为建筑足迹)大约需要 30 秒(时间太长)。
我也尝试过使用mplPath如下:
import matplotlib.path as mplPath
building_arrays = [np.array(data['features'][i]['geometry']['coordinates'][0])
for i, v in enumerate(tqdm(data['features']))]
bbPath_list = [mplPath.Path(building)
for building in tqdm(building_arrays)]
for b in tqdm(bbPath_list):
if b.contains_point((-71.1273842, 42.3847423)):
print(b)
Run Code Online (Sandbox Code Playgroud)
这大约需要 6 秒。一个改进,但考虑到我需要的映射量,仍然有点慢。 …
python ×2
amazon-s3 ×1
api ×1
aws-lambda ×1
docker ×1
geopandas ×1
javascript ×1
performance ×1
python-3.x ×1
react-native ×1
react-query ×1
reactjs ×1
scrapy ×1
shapely ×1
web-scraping ×1