Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prod #1

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions DB/redis_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# coding: utf-8
# Create by Annhuny On 2020-01-07 01:42
# File Name : redis_session.py
import redis

from config import conf


redis_cfg = conf.get('DB').get('redis')
r_session = redis.Redis(**{
'host': redis_cfg.get('host'),
'port': redis_cfg.get('port'),
'password': redis_cfg.get('password')
})
31 changes: 29 additions & 2 deletions DB/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,36 @@
# Create by Annhuny On 2019-12-28 01:58
# File Name : service.py
from DB.sqlalchemy_session import session
from Models.models import SeasonStatistic, Season, DailyStatistic


def get_season_statistic_by_season_id(season_id, order_by):
session.query()
# season
from utils.tools import default_datetime_format


def get_season_list():
return session.query(Season).all()


def get_season_by_id(season_id):
return session.query(Season).filter_by(id=season_id).first()


def get_season_statistic_by_season_id(season_id):
return session.query(SeasonStatistic).filter_by(seasonId=season_id).all()


# daily
def get_daily_statistic_by_player_tag_and_datetime_tag_list(player_tag, datetime_tag_list):
datetime_tag_list = [item.strftime(default_datetime_format) for item in datetime_tag_list]
return session.query(DailyStatistic)\
.filter_by(tag=player_tag)\
.filter(DailyStatistic.datetimeTag.in_(datetime_tag_list)) \
.order_by(DailyStatistic.id.asc()) \
.all()


def get_daily_statistic_by_datetime_tag(datetime_tag):
return session.query(DailyStatistic)\
.filter_by(datetimeTag=datetime_tag)\
.all()
10 changes: 7 additions & 3 deletions DB/sqlalchemy_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
from config import conf


def to_dict(self):
return {c.name: getattr(self, c.name, None) for c in self.__table__.columns}


Base = declarative_base()
Base.to_dict = to_dict

# 初始化数据库连接
db_conf = conf.get('DB').get('mysql')
engine = create_engine('mysql+mysqlconnector://{user}:{password}@{ip}:{port}/{database}'.format(**{
'user': db_conf.get('user'),
'password': db_conf.get('password'),
'ip': db_conf.get('ip'),
'port': db_conf.get('port'),
'database': db_conf.get('database'),
}))
}), pool_size=5, max_overflow=10, pool_timeout=30, pool_pre_ping=True)

# 创建DBSession类型:
DBSession = sessionmaker(bind=engine)
session = DBSession()
session = DBSession(expire_on_commit=False)
22 changes: 22 additions & 0 deletions Models/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# coding: utf-8
# Create by Annhuny On 2019-12-28 19:16
# File Name : enums.py
from enum import Enum


class ErrEnums(Enum):
TestError = (200, 'test')
DatetimeParamsError = (101, '开始时间晚于结束时间')
IntervalStepError = (102, '由于时间采集粒度为2小时,间隔必须为2的整数倍')
DatetimeIntervalError = (103, '间隔过多,最大行数24')


class SeasonStatus(object):
INACTIVE = 0
ACTIVE = 1


class IntervalType(object):
HOURS = 1
DAY = 2
MONTH = 3
32 changes: 23 additions & 9 deletions Models/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
#!/usr/bin/env python
# Create by Annhuny On 2019-12-25 20:04
# File Name : Members.py
from sqlalchemy import Column, String, Integer, JSON, DateTime
from sqlalchemy import Column, String, Integer, JSON, DateTime, func

from DB.sqlalchemy_session import Base


class Member(Base):
__tablename__ = 'members'
class Season(Base):
__tablename__ = 'season'

id = Column(Integer, primary_key=True)
name = Column(String)
status = Column(Integer)
createAt = Column(DateTime, server_default=func.now())
updateAt = Column(DateTime, server_default=func.now())


class SeasonStatistic(Base):
__tablename__ = 'season_statistic'

id = Column(Integer, primary_key=True)
seasonId = Column(Integer)
tag = Column(String)
name = Column(String)
role = Column(String)
Expand All @@ -19,16 +30,21 @@ class Member(Base):
versusTrophies = Column(Integer)
clanRank = Column(Integer)
previousClanRank = Column(Integer)
attackWins = Column(Integer)
donations = Column(Integer)
donationsReceived = Column(Integer)
createAt = Column(DateTime, server_default=func.now())
updateAt = Column(DateTime, server_default=func.now())


class FlowingData(Base):
__tablename__ = 'flowing_data'
class DailyStatistic(Base):
__tablename__ = 'daily_statistic'

id = Column(Integer, primary_key=True)
tag = Column(String)
name = Column(String)
expLevel = Column(Integer)
townHallLevel = Column(Integer)
trophies = Column(Integer)
versusTrophies = Column(Integer)
attackWins = Column(Integer)
Expand All @@ -38,8 +54,6 @@ class FlowingData(Base):
elixir = Column(Integer)
darkElixir = Column(Integer)
datetimeTag = Column(DateTime)




createAt = Column(DateTime, server_default=func.now())
updateAt = Column(DateTime, server_default=func.now())

8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
手游部落冲突

- 折线图
- 赛季统计

让我看看是哪些伸手党整天白嫖

![demo](./demo.png)
2 changes: 1 addition & 1 deletion asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coc.settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

application = get_asgi_application()
4 changes: 3 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
#!/usr/bin/env python
# Create by Annhuny On 2019-12-27 16:17
# File Name : config.py
Expand All @@ -7,7 +8,8 @@

import yaml

from settings import PROJECT_ROOT_DIR, CFG_FILE_NAME
PROJECT_ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
CFG_FILE_NAME = 'config.yml'


class ConfSingleton(object):
Expand Down
Binary file added demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@


class CustomError(Exception):
pass
def __init__(self, err):
self.code = err.value[0]
self.msg = err.value[1]

def __str__(self):
return 'code: {}, msg:{}'.format(self.code, self.msg)


DEFAULT_ERR_CODE = -1
93 changes: 50 additions & 43 deletions initdb.sql
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
create table if not exists `season_statistic` (
`id` varchar (15) not null default '' primary key,
`seasonId` integer not null default 0,
`tag` varchar (64) not null default '',
`name` varchar (64) not null default '',
`role` varchar (16) not null default '',
`expLevel` integer unsigned not null default 0,
`league` varchar (4048) not null default '',
`trophies` integer unsigned not null default 0,
`versusTrophies` integer unsigned not null default 0,
`clanRank` integer unsigned not null default 0,
`previousClanRank` integer unsigned not null default 0,
`attackWins` integer unsigned not null default 0,
`donations` integer unsigned not null default 0,
`donationsReceived` integer unsigned not null default 0,
key `idx_seasonId` (`seasonId`)
) engine=innodb default charset=utf8;
CREATE TABLE `season_statistic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`seasonId` int(11) NOT NULL DEFAULT '0',
`tag` varchar(64) NOT NULL DEFAULT '',
`name` varchar(64) NOT NULL DEFAULT '',
`role` varchar(16) NOT NULL DEFAULT '',
`expLevel` int(10) unsigned NOT NULL DEFAULT '0',
`league` varchar(4048) NOT NULL DEFAULT '{}',
`trophies` int(10) unsigned NOT NULL DEFAULT '0',
`versusTrophies` int(10) unsigned NOT NULL DEFAULT '0',
`clanRank` int(10) unsigned NOT NULL DEFAULT '0',
`previousClanRank` int(10) unsigned NOT NULL DEFAULT '0',
`attackWins` int(10) NOT NULL DEFAULT '0',
`donations` int(10) unsigned NOT NULL DEFAULT '0',
`donationsReceived` int(10) unsigned NOT NULL DEFAULT '0',
`createAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updateAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_seasonId` (`seasonId`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


create table if not exists `season` (
`id` varchar (15) not null default '' primary key,
`name` varchar (255) not null default '' unique key,
`status` integer not null default 0,
`createAt` datetime not null default current_timestamp,
`updateAt` datetime not null default current_timestamp on update current_timestamp,
unique key `unq_name` (`name`)
) engine=innodb default charset=utf8;
CREATE TABLE `season` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`status` int(11) NOT NULL DEFAULT '0',
`createAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updateAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`),
UNIQUE KEY `unq_name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


create table if not exists `flowing_data` (
`id` integer auto_increment primary key,
`tag` varchar (15) not null default '',
`expLevel` integer unsigned not null default 0,
`trophies` integer unsigned not null default 0,
`versusTrophies` integer unsigned not null default 0,
`attackWins` integer unsigned not null default 0,
`donations` integer unsigned not null default 0,
`donationsReceived` integer unsigned not null default 0,
`gold` integer unsigned not null default 0,
`elixir` integer unsigned not null default 0,
`darkElixir` integer unsigned not null default 0,
`dateTimeTag` datetime not null default current_timestamp,
`createAt` datetime not null default current_timestamp,
`updateAt` datetime not null default current_timestamp on update current_timestamp,
key `idx_dateTimeTag` (`dateTimeTag`),
key `idx_tag` (`tag`)
) engine=innodb default charset=utf8;
CREATE TABLE `daily_statistic` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tag` varchar(15) NOT NULL DEFAULT '',
`name` varchar(64) NOT NULL DEFAULT '',
`expLevel` int(10) unsigned NOT NULL DEFAULT '0',
`trophies` int(10) unsigned NOT NULL DEFAULT '0',
`versusTrophies` int(10) unsigned NOT NULL DEFAULT '0',
`attackWins` int(10) unsigned NOT NULL DEFAULT '0',
`donations` int(10) unsigned NOT NULL DEFAULT '0',
`donationsReceived` int(10) unsigned NOT NULL DEFAULT '0',
`gold` int(10) unsigned NOT NULL DEFAULT '0',
`elixir` int(10) unsigned NOT NULL DEFAULT '0',
`darkElixir` int(10) unsigned NOT NULL DEFAULT '0',
`dateTimeTag` datetime NOT NULL,
`createAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updateAt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_dateTimeTag` (`dateTimeTag`),
KEY `idx_tag` (`tag`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
Loading