특정 DB 에 있는 테이블의 스키마가 필요하다는 형의 연락에,
간단하게 table name, column name, column type 을 보여주는 파이썬 코드를 만들어보았음

__author__ = 'novice'

import pymysql

host_addr = '아이피'
user_acc = '디비 계정'
passwd = '비번'
db_name = '데이터베이스'

conn = pymysql.connect(host=host_addr, user=user_acc, passwd=passwd, db=db_name)

cur = conn.cursor(pymysql.cursors.DictCursor)
cur.execute('select * from information_schema.tables where table_schema = %s', db_name)

for row in cur:
table_name = row['TABLE_NAME']

print('-------------------------------------------------------------------------------------')
print('TABLE NAME : ', table_name)
print('-------------------------------------------------------------------------------------')

t_cur = conn.cursor(pymysql.cursors.DictCursor)
t_cur.execute('select * from information_schema.columns where table_schema = %s and table_name = %s',
(db_name, table_name))

for columns in t_cur:
print(columns['COLUMN_NAME'], '\t', columns['COLUMN_TYPE'], )

print('-------------------------------------------------------------------------------------')
print()

t_cur.close()

cur.close()
conn.close()

끝!


플레이어가 성장하는 도중 어디서 이탈을 많이 하는지 측정하기 위해, Stage 진행에 대한 Funnel 정보 (이하, Stage Funnel) 를 그려봤다.
대부분의 아이디어는 컨설팅을 받을 때 배운 것들이고, 그때 했던 것을 복기하는 차원에서 혼자서 해봤다.
우선 간단하게 데이터 정제를 DB 쿼리로 해봤고, 특정 스테이지 기준으로 더이상 정보가 없는 경우 해당 스테이지에 머물렀다고 간주했음
기간이 영향을 줄 수 있는데, 우선은 Funnel 을 그리는데에 집중했고, 이탈을 정의하는 방법에 따라 쿼리의 Where 절을 변경하면 되겠다.
  • 생각의 전개

    • 플레이어의 성장을 측정하기 위해 성장 기준을 무엇으로 삼을지 고민

    • “레벨", "스테이지 진행" 중 "스테이지 진행”을 선택

      • 레벨은 직관적이지만 후반 구간일수록 대변하는 플레이어 집단의 특성이 분산될 것으로 예상

        예를 들어, 특정 레벨 구간 N 의 플레이어 집단에 대해
        소유한 재화의 평균을 M(N), 표준편차를 D(N) 이라고 하고,
        3Lv과 50Lv 을 서로 비교해보면,
        M(3) 과 M(50) 의 관계는 예측하기 어렵겠지만, 적어도 D(3) < D(50) 일 가능성이 크다고 생각된다

        요약) 플레이를 많이 함 -> 재화 획득 / 소진을 여러번 경험함 -> 보유 재화의 분산이 큼

      • 스테이지 진행도 뒤로 갈수록 레벨과 비슷한 양상을 보이게 되나,
        레벨보다는 훨씬 덜 할 것으로 판단되는데,
        특정 스테이지를 플레이 해도 레벨이 오르지 않는 경우가 많은 것을 생각해보면 그저 당연한 일일 뿐..

    • 특정 스테이지에 머물러 있다는 정보도 중요하지만,
      사실 “왜” 머물러 있는지가 가장 중요할거라고 생각하고,
      “왜” 에 대한 가장 단순한 접근으로, 머물러 있기 직전에 해당 스테이지를 클리어 했는지 여부를 기준으로 그려봤음

    • 실패했는데 나가는것과 성공했는데 나가는 것이 어떤 의미를 갖고 있을지 고민중...

library(RMySQL)

# connect to db
conn <- dbConnect(MySQL(), user='', password='', dbname='', host='')

# select tidy data for stage funnel from stats log db
rs <- dbSendQuery(conn, "select cid, max(cd6) as field, 'lose' as result from _stats_log
     where ts > '2015-01-01 00:00:00'
          and ea like '%lose%'
          and el = 'player'
          and ec = 'combat'
     group by cid
union all
select cid, max(cd6), 'win' as result from _stats_log
     where ts > '2015-01-01 00:00:00'
          and ea like '%win%'
          and el = 'player'
          and ec = 'combat'
     group by cid;
")

# fetch result set
table <- fetch(rs, -1)

# clear db resources
dbClearResult(rs)
dbDisconnect(conn)

# result and field are factor
table$result <- as.factor(table$result)
table$field <- as.factor(table$field)

# show summary information
summary(table)

# draw result
library(ggplot2)

p <- ggplot(table, aes(field, fill=result))
p + geom_bar(position="dodge")



+ Recent posts