This file contains hidden or 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
import pypinyin | |
from pypinyin import pinyin | |
def check_poem(poem, cnt=False, vowel=False, tone=False): | |
# 五言/七言 律诗/绝句 字数检查(不考虑鹅鹅鹅特殊场景) | |
l=poem.split('。') | |
l=sum([i.split(',') for i in l if i],[]) | |
l_cnt=[len(i) for i in l] | |
if len(set(l_cnt))!=1 or l_cnt[0] not in [5,7]: | |
if cnt: | |
return 101 |
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import folium | |
from pykalman import KalmanFilter | |
from rdp import rdp | |
import numpy as np | |
def kalm(l): | |
''' |
This file contains hidden or 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
from xml.etree import ElementTree | |
headers = {'user-agent': 'my-app/0.0.1'} | |
x=requests.get('https://www.douban.com/feed/review/movie',headers=headers,timeout=300) | |
rt=ElementTree.fromstring(x.text) | |
for i in rt[0]: | |
if not i.tag=='item': | |
continue | |
t=i.find('description').text.split('\n') | |
if t[2]=='评价: 力荐': | |
print(t[1].split('评论: ')[1]) |
This file contains hidden or 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
# style, display etc. | |
def ipy_width(w='90%'): | |
import IPython | |
IPython.core.display.display(IPython.core.display.HTML('<style>.container { width:'+w+' !important; }</style>')) | |
def plotly_layout(): | |
return go.Layout( | |
barmode='stack', | |
paper_bgcolor='rgb(199,237,204)', |
This file contains hidden or 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
pmodel={} | |
for ptype in ['child','male','female']: | |
samples=[] | |
p='/data/audio/'+ptype | |
for i in tqdm(os.listdir(p)): | |
try: | |
s1,_=librosa.load(p+i,sr=16000) | |
s1,_=librosa.effects.trim(s1,top_db=12) | |
# s1=librosa.feature.melspectrogram(s1,sr=16000,n_fft=256) | |
s1=librosa.feature.mfcc(s1,n_mfcc=20) |
This file contains hidden or 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
# with t of fitted model | |
# call score(sample.T,t.means_,t.precisions_cholesky_,t.covariance_type,t.weights_) | |
def logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False): | |
if b is not None: | |
a, b = np.broadcast_arrays(a, b) | |
if np.any(b == 0): | |
a = a + 0. # promote to at least float | |
a[b == 0] = -np.inf |
This file contains hidden or 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
# mini librosa equivalent for trim & mfcc | |
# work with fftpack folder under scipy for dct (remove all scipy. within files) | |
from numpy.lib.stride_tricks import as_strided | |
import six | |
import numpy as np | |
from fftpack import dct | |
MAX_MEM_BLOCK = 2**8 * 2**10 |
This file contains hidden or 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
#1 | |
from PyAstronomy import pyasl | |
beq = pyasl.BSEqSamp() | |
nstd, nstdstd = beq.betaSigma(wav, 1, 1, returnMAD=True) | |
# or simply | |
b = [ np.sum(wav[i:i+3] * np.array([1, -2, 1])) for i in range(len(wav) - 2)] | |
# boost speed for j==1:: b=[ wav[i]+wav[i+2]-wav[i+1] for i in range(len(wav) - 2)] | |
b /= np.sqrt(6.0) | |
bvar = np.sum(b**2) *1e5 / len(b) | |
# bvarvar = 2. * bvar**2 / len(b) * 1.944 |
This file contains hidden or 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
!yum install snappy-devel -y | |
!pip3 install kafka-python | |
from kafka import KafkaConsumer,TopicPartition | |
c = KafkaConsumer(bootstrap_servers="ip1:10005,ip2:10069", | |
client_id='cg_atta_', | |
group_id='cg_atta_') | |
c.assign([TopicPartition('U_TOPIC_0000',1)]) | |
msg=next(c).value.decode('gbk') | |
from kafka import KafkaProducer |
This file contains hidden or 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
import pymongo | |
client = pymongo.MongoClient('mongodb://ip:27017',username='usr', password='pwd') | |
print(client.list_database_names()) | |
client = client['db_name'] | |
print(client.list_collection_names()) | |
client=client['col_name'] | |
x=spark.sql('select uid,p1,p2 from hdb.htable where ds=date').rdd.collect() | |
t=x[0].asDict() | |
mocol.insert_one({i:t[i] for i in t if t[i]}) | |
mocol.count_documents({'user_id':{"$gt":0}}) |
NewerOlder