Beispiel #1
0
def printSummary(file: str):
    functions = get_functions(file)
    plag_lines = 0
    plag_groups = {}
    for f in functions:
        chk = (file, f)
        for j in func_clusters[1:]:
            if chk in j:
                plag_lines += len(
                    list(filter(lambda x: x, functions[f].split("\n"))))
                plag_groups[f] = j
                break

    plag_fraction = plag_lines / get_parsed_lines(file)
    print(f"{file} is estimated to be {plag_fraction*100:.2f}% plagiarised")
    if plag_fraction > 0.005:
        print("The following possible sources for plagiarism were detected -")
        for func, sources in plag_groups.items():
            print(f"{func}:")
            for source in sources:
                if source[0] != file:
                    print(f"\t{source[0]}\t:{source[1]}")
Beispiel #2
0
import matplotlib.pyplot as plt
from utilities import BiddingEnvironment, Subcampaign, MultiChoiceKnapsack, Experiment, print_clairvoyants
from functions import get_functions

print_functions = True

##########################
###  BUILDING PROGRAM  ###
##########################

T = 70
num_arms = 20
daily_budget = 1
discrete_bid_per_arm = np.linspace(0, daily_budget, num_arms + 1, dtype=float)

classes_functions = get_functions()

sub_campaigns = []
i = 1
sc_id = 1
a = [1, 1, 1]
for sub_functions in classes_functions:
    sub_campaigns.append(
        Subcampaign(sub_functions,
                    sub_campaign_id=sc_id,
                    func_numbers=tuple([a[j] * i + j for j in range(len(a))])))
    i += 3
    sc_id += 1
bidding_environment = BiddingEnvironment(sub_campaigns)

##################################
Beispiel #3
0
def revocation(msg):
    mytime = time.localtime()  # 这儿获取的是本地时间
    # 获取用于展示给用户看的时间 2017/03/03 13:23:53
    msg_time_touser = mytime.tm_year.__str__() \
                      + "/" + mytime.tm_mon.__str__() \
                      + "/" + mytime.tm_mday.__str__() \
                      + " " + mytime.tm_hour.__str__() \
                      + ":" + mytime.tm_min.__str__() \
                      + ":" + mytime.tm_sec.__str__()
    msg_from_user_name = msg['FromUserName']
    msg_id = msg['MsgId']  # 消息ID
    msg_time = msg['CreateTime']  # 消息时间
    msg_from = itchat.search_friends(
        userName=msg['FromUserName'])['NickName']  # 消息发送人昵称
    msg_type = msg['Type']  # 消息类型
    msg_content = None  # 根据消息类型不同,消息内容不同
    msg_url = None  # 分享类消息有url
    # 图片 语音 附件 视频,可下载消息将内容下载暂存到当前目录
    wx_msg_text = msg['Text']
    if msg['Type'] == 'Text':

        msg_content = wx_msg_text

        global autoReplyFlag, timerSet, noReply, t  # 状态标志位
        print(wx_msg_text)
        if is_msg_from_myself(msg['FromUserName']):
            print("Replied!!")
            autoReplyFlag = False
            noReply = False
            try:
                t.cancel()
                print("Timer Canceled")
                timerSet = False
            except:
                pass
            return None

        if autoReplyFlag:
            # 查看功能
            if wx_msg_text == '所有功能':
                return '您可以使用下列功能:\n' + get_functions()
            elif wx_msg_text[:1] == r'#':
                return get_example(wx_msg_text[1:])
            elif wx_msg_text[:1] == r'@':
                print('do nothing')
            else:
                # 为了保证在图灵Key出现问题的时候仍旧可以回复,这里设置一个默认回复
                default_reply = 'I received: ' + wx_msg_text
                # 如果图灵Key出现问题,那么reply将会是None
                reply = get_response(wx_msg_text)
                # a or b的意思是,如果a有内容,那么返回a,否则返回b
                # 有内容一般就是指非空或者非None,你可以用`if a: print('True')`来测试
                if AUTO_REPLAY:
                    return '小K: ' + reply or '小K: ' + default_reply
        else:
            noReply = True
            if not timerSet:
                # if time.time()-noReplyStartTime >= 120:
                print("Timer setting")
                t = Timer(12, send_busy_status, [msg['FromUserName']])
                t.start()
                timerSet = True

    elif msg['Type'] == 'Picture':
        msg_content = msg['FileName']

        try:
            # 下载图片
            wx_msg_text(msg['FileName'])
        except OSError:
            ''
    elif msg['Type'] == 'Card':
        msg_content = msg['RecommendInfo']['NickName'] + r" 的名片"
    elif msg['Type'] == 'Map':
        x, y, location = re.search(
            "<location x=\"(.*?)\" y=\"(.*?)\".*label=\"(.*?)\".*",
            msg['OriContent']).group(1, 2, 3)
        if location is None:
            msg_content = r"纬度->" + x.__str__() + " 经度->" + y.__str__()
        else:
            msg_content = r"" + location
    elif msg['Type'] == 'Sharing':
        msg_content = wx_msg_text
        msg_url = msg['Url']
    elif msg['Type'] == 'Recording':
        msg_content = msg['FileName']
        wx_msg_text(msg['FileName'])
    elif msg['Type'] == 'Attachment':
        msg_content = r"" + msg['FileName']
        wx_msg_text(msg['FileName'])
    elif msg['Type'] == 'Video':
        msg_content = msg['FileName']
        wx_msg_text(msg['FileName'])
    elif msg['Type'] == 'Friends':
        msg_content = wx_msg_text

    # friend = itchat.search_friends(userName=msg['FromUserName'])
    # itchat.send(r"Friend:%s -- %s    "
    #             r"Time:%s    "
    #             r" Message:%s" % (friend['NickName'], friend['RemarkName'], msg_time_touser, msg_content),
    #             toUserName='******')

    if msg['Type'] != 'Text':
        if AUTO_REPLAY:
            itchat.send("小K已收到您的消息,主人稍后回复!\n\t时间: %s\n\t内容: %s" %
                        (msg_time_touser, msg_content),
                        toUserName=msg['FromUserName'])

    # 更新字典
    # {msg_id:(msg_from,msg_time,msg_time_touser,msg_type,msg_content,msg_url)}
    msg_dict.update({
        msg_id: {
            "msg_from": msg_from,
            "msg_time": msg_time,
            "msg_time_touser": msg_time_touser,
            "msg_type": msg_type,
            "msg_content": msg_content,
            "msg_url": msg_url,
            "msg_from_user_name": msg_from_user_name
        }
    })
    # 清理字典
    clear_timeout_msg()
file_funcs = {}
reverse_map = {}

files = []

for i in range(1, 9):
    files += glob.glob(f"data/{i}*.c")

tot = len(files)
with open("missing_log.txt", "w") as log, open("used_log.txt", "w") as used:
    for idx, filename in enumerate(files):
        func_vectors = {}
        print(f"{idx+1}/{tot}")
        try:
            func = get_functions(filename)
            for f in func:
                vec = get_vector(func[f], is_file=False)
                func_vectors[f] = vec
                try:
                    reverse_map[tuple(vec)].append((filename, f))
                except:
                    reverse_map[tuple(vec)] = [(filename, f)]

            file_funcs[filename] = func_vectors
            used.write(filename + "\n")
        except:
            log.write(filename + "\n")

with open("func_vec_map.pkl", "wb") as f:
    pickle.dump(file_funcs, f)