-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import glob | ||
import subprocess | ||
from datetime import timedelta, datetime | ||
|
||
lengths = [] | ||
LOCATION = "/Users/seungwonjeong/Desktop/sparta/Week1" # '영상이 들어있는 폴더 경로' | ||
EXTENSION = "mp4" # 확장자 | ||
|
||
def get_length(filename): | ||
ffmpeg = subprocess.Popen( | ||
['ffmpeg', '-i', filename], | ||
stderr=subprocess.PIPE | ||
) | ||
grep = subprocess.Popen( | ||
['grep', 'Duration'], | ||
stdin=ffmpeg.stderr, | ||
stdout=subprocess.PIPE | ||
) | ||
awk = subprocess.Popen( | ||
['awk', "{print $2}"], | ||
stdin=grep.stdout, | ||
stdout=subprocess.PIPE | ||
) | ||
trim = subprocess.Popen( | ||
['tr', '-d', ','], | ||
stdin=awk.stdout, | ||
stdout=subprocess.PIPE | ||
) | ||
for line in trim.stdout: | ||
# 딱 첫 번째 줄만 출력. | ||
return line.decode('utf-8') | ||
|
||
# root_dir needs a trailing slash (i.e. /root/dir/) | ||
for filename in glob.iglob(LOCATION + f'**/*.{EXTENSION}', recursive=True): | ||
lengths.append(get_length(filename)) | ||
|
||
|
||
# 시간 parse | ||
deltas = [] | ||
for elem in lengths: | ||
datetime = datetime.strptime(elem[:-4], '%H:%M:%S') | ||
delta = timedelta(hours=datetime.hour, minutes=datetime.minute, seconds=datetime.second) | ||
deltas.append(delta) | ||
|
||
# sum | ||
print(sum(deltas, timedelta(0))) |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
layout: single | ||
title: "좋아요에 관한 간단한 고찰" | ||
date: 2021-06-20 11:10:03 +0900 | ||
categories: [Python, Aws] | ||
--- | ||
|
||
## 게시글에 '좋아요' | ||
좋아요, 이게 간단해 보이지만 생각보다 엄청 복잡한 기능입니다. | ||
퀄리티 있는 좋아요 기능을 구현하기 위해서는 다음과 같은 문제를 해결해야 합니다. | ||
|
||
* 새로운 '좋아요' 값은 기존 '좋아요' 값에 영향을 받습니다. (new_like = old_like + 1) | ||
그렇다면 동시성 문제를 해결하기 위해 Lock 을 걸어야 할까? 같은 고민을 하게 되죠. | ||
|
||
* 다양한 종류의 테이블에 좋아요를 할 수 있어야 합니다. 요즘 SNS 보면 댓글에도 좋아요, 게시글에도 좋아요 | ||
별의별 종류의 테이블에 좋아요를 할 수 있죠. 이건 RDBMS 에서 어떻게 모델링을 해야 하는 걸까요? | ||
|
||
* 좋아요는 쓰기보다 읽기가 훨씬 많은 데이터 입니다. 따라서 좋아요 수를 계산하기 위해 record 를 매 번 세는 것은 | ||
효율적이지 않습니다. 총 좋아요 값을 저장할 필요가 있습니다. | ||
|
||
* 운영 측면에서 좋아요 수를 가지고 통계를 내기에 편리해야 합니다. | ||
|
||
|
||
## 좋아요를 구현하는 다양한 방법들 | ||
|
||
|
||
### 좋아요 테이블이 수많은 테이블과 직접 foreign key 를 맺는 방법 | ||
* likes 가 수많은 foreign key 중 하나만 값을 갖고 나머지는 NULL 일 것을 보장해야 합니다. mysql 만으로는 할 수 없고, | ||
코드 상에서 제한을 두어야겠죠? | ||
|
||
|
||
|
||
### Document 에 좋아요를 하는 방법 | ||
|
||
* 공통된 부모를 두고, 부모에 좋아요를 연결 | ||
* NULL 인 foreign key 가 없습니다. | ||
* 좋아요 수를 구하기 위해서 바로 likes 를 join 할 수 없고, documents 를 중간에 join 해야 합니다. | ||
* documents 에 like_cnt 를 둘 수 있습니다. | ||
|
||
|
||
|
||
|
||
## 운영 측면에서 통계 내기 | ||
|
||
|
||
### 좋아요가 가장 많은 게시글은 무엇인가? | ||
|
||
간단한 쿼리로 알아낼 수 있습니다. | ||
```sql | ||
SELECT MAX(id) FROM likes group by article_id; | ||
``` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
### 좋아요 수를 읽어들이지 않고, 바로 UPDATE 를 치는 방법 | ||
Lock 을 걸지 않고 문제를 해결하는 아주 깔끔한 방법입니다. | ||
|
||
|
||
|
||
|
||
|
||
|