File size: 3,206 Bytes
dfcdf7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# coding: utf-8

# In[ ]:


import os
import sys
from random import randint
import time
import uuid
import argparse
sys.path.append(os.path.abspath("../supv"))
from matumizi.util import *
from mcclf import *

def  genVisitHistory(numUsers, convRate, label):
    for i in range(numUsers):
        userID = genID(12)
        userSess = []
        userSess.append(userID)

        conv = randint(0, 100)
        if (conv < convRate):
            #converted
            if (label):
                if (randint(0,100) < 90):
                    userSess.append("T")
                else:
                    userSess.append("F")


            numSession = randint(2, 20)
            for j in range(numSession):
                sess = randint(0, 100)
                if (sess <= 15):
                    elapsed = "H"
                elif (sess > 15 and sess <= 40):
                    elapsed = "M"
                else:
                    elapsed = "L"

                sess = randint(0, 100)
                if (sess <= 15):
                    duration = "L"
                elif (sess > 15 and sess <= 40):
                    duration = "M"
                else:
                    duration = "H"

                sessSummary = elapsed + duration
                userSess.append(sessSummary)


        else:
            #not converted
            if (label):
                if (randint(0,100) < 90):
                    userSess.append("F")
                else:
                    userSess.append("T")

            numSession = randint(2, 12)
            for j in range(numSession):
                sess = randint(0, 100)
                if (sess <= 20):
                    elapsed = "L"
                elif (sess > 20 and sess <= 45):
                    elapsed = "M"
                else:
                    elapsed = "H"

                sess = randint(0, 100)
                if (sess <= 20):
                    duration = "H"
                elif (sess > 20 and sess <= 45):
                    duration = "M"
                else:
                    duration = "L"

                sessSummary = elapsed + duration
                userSess.append(sessSummary)

        print(",".join(userSess))

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--op', type=str, default = "none", help = "operation")
    parser.add_argument('--nuser', type=int, default = 100, help = "num of users")
    parser.add_argument('--crate', type=int, default = 10, help = "concersion rate")
    parser.add_argument('--label', type=str, default = "false", help = "whether to add label")
    parser.add_argument('--mlfpath', type=str, default = "false", help = "ml config file")
    args = parser.parse_args()
    op = args.op

    if op == "gen":	
        numUsers = args.nuser
        convRate = args.crate

        label = args.label == "true"
        genVisitHistory(numUsers, convRate, label)

    elif op == "train":
        model = MarkovChainClassifier(args.mlfpath)
        model.train()

    elif op == "pred":
        model = MarkovChainClassifier(args.mlfpath)
        model.predict()

    else:
        exitWithMsg("invalid command)")