일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- API
- Mac
- matplotlib
- Kafka
- zip 파일 암호화
- Test
- 900gle
- MySQL
- Java
- TensorFlow
- aggs
- analyzer test
- springboot
- license delete
- plugin
- aggregation
- Elasticsearch
- licence delete curl
- Python
- 차트
- token filter test
- zip 암호화
- License
- docker
- ELASTIC
- query
- high level client
- 파이썬
- sort
- flask
Archives
- Today
- Total
개발잡부
[python] 숫자 3자리 마다 콤마(,)찍기 - format 본문
반응형
결론부터
format(buckets["doc_count"],',')
그렇다 이렇게 하면 숫자 3자리 마다 콤마(,) 가 찍힌다.
날짜구간: 2024-02-05 ~ 2024-02-06
확장검색 전체: 114,274건
* 일반 쿼리: 113,675건
* 슬로우 쿼리: 599건
- 확장검색 상세 -
* 0ms ~ 1000ms: 111,250건
* 1000ms ~ 2000ms: 1,708건
* 2000ms ~ 3000ms: 717건
* 3000ms ~ : 599건
- 확장검색 슬로우 상세 -
* 3000ms ~ 4000ms: 325건
* 4000ms ~ 5000ms: 147건
* 5000ms ~ : 127건
- 검색결과 상세 -
* 1 ~ 100: 58,322건
* 100 ~ 1000: 12,161건
* 1000 ~ 10000: 25,137건
* 10000 ~ : 18,654건
전체코드
# -*- coding: utf-8 -*-
import time
import json
from datetime import datetime, timedelta
import requests
import ssl
import urllib3
from time import sleep
from elasticsearch import Elasticsearch
print(ssl.OPENSSL_VERSION)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def get_keyword():
f_v = open("./data/search_report.txt",'w')
now =datetime.now() - timedelta(days=1)
start = now.date().strftime('%Y-%m-%d %H:%M:%S')
start_v = now.date().strftime('%Y-%m-%d')
end_date = now + timedelta(days=1)
end = end_date.date().strftime('%Y-%m-%d %H:%M:%S')
end_v = end_date.date().strftime('%Y-%m-%d')
with open(LOG) as index_file:
source = index_file.read().strip()
query = source.replace("{start}", start).replace("{end}", end)
response = log_client.search(index=LOG_INDEX, body=query)
keys = []
print("== log == ")
print("날짜구간: "+ start_v + " ~ " + end_v)
f_v.write("날짜구간: "+ start_v + " ~ " + end_v)
f_v.write("\n")
f_v.write("확장검색 전체: " + str(format(response["hits"]["total"]["value"],',')) + "건\n")
for buckets in response["aggregations"]["COUNT"]["buckets"]:
f_v.write(" * "+buckets["key"] + ": ")
f_v.write(str(format(buckets["doc_count"],',')) + "건\n")
f_v.write("\n")
f_v.write(" - 확장검색 상세 - \n")
for buckets in response["aggregations"]["NORMAL"]["buckets"]:
f_v.write(" * "+buckets["key"] + ": ")
f_v.write(str(format(buckets["doc_count"],',')) + "건\n")
f_v.write("\n")
f_v.write(" - 확장검색 슬로우 상세 - \n")
for buckets in response["aggregations"]["SLOW"]["buckets"]:
f_v.write(" * "+buckets["key"] + ": ")
f_v.write(str(format(buckets["doc_count"],',')) + "건\n")
f_v.write("\n")
f_v.write(" - 검색결과 상세 - \n")
for buckets in response["aggregations"]["RECALL"]["buckets"]:
f_v.write(" * "+buckets["key"] + ": ")
f_v.write(str(format(buckets["doc_count"],',')) + "건\n")
f_v.close()
##### MAIN SCRIPT #####
if __name__ == '__main__':
LOG_INDEX = "home-search-query-log"
LOG = "./sql/search-log.json"
log_client = Elasticsearch("https://id:pw@host:port/", ca_certs=False,
verify_certs=False)
print("Start.")
get_keyword()
print("END.")
반응형