@ -1,57 +0,0 @@ |
|||
package main |
|||
|
|||
import "fmt" |
|||
|
|||
//Color struct, defines the color
|
|||
type Color struct{} |
|||
|
|||
var c Color |
|||
|
|||
//DarkGray color
|
|||
func (c Color) DarkGray(t string) { |
|||
fmt.Print("\x1b[30;1m") //dark gray
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Red color
|
|||
func (c Color) Red(t string) { |
|||
fmt.Print("\x1b[31;1m") //red
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Green color
|
|||
func (c Color) Green(t string) { |
|||
fmt.Print("\x1b[32;1m") //green
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Yellow color
|
|||
func (c Color) Yellow(t string) { |
|||
fmt.Print("\x1b[33;1m") //yellow
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Blue color
|
|||
func (c Color) Blue(t string) { |
|||
fmt.Print("\x1b[34;1m") //blue
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Purple color
|
|||
func (c Color) Purple(t string) { |
|||
fmt.Print("\x1b[35;1m") //purple
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
|||
|
|||
//Cyan color
|
|||
func (c Color) Cyan(t string) { |
|||
fmt.Print("\x1b[36;1m") //cyan
|
|||
fmt.Println(t) |
|||
fmt.Print("\x1b[0m") //defaultColor
|
|||
} |
@ -0,0 +1,5 @@ |
|||
item1 |
|||
item2 |
|||
item3 |
|||
item4 |
|||
item5 |
@ -1,5 +1,4 @@ |
|||
{ |
|||
"ip": "127.0.0.1", |
|||
"database": "goRecommend", |
|||
"collection": "userHistory" |
|||
"database": "goRecommend" |
|||
} |
@ -1,6 +1,15 @@ |
|||
package main |
|||
|
|||
type UserModel struct { |
|||
Userid string |
|||
History []string |
|||
ID string `json:"id"` |
|||
Age int `json:",string"` |
|||
Actions []string |
|||
} |
|||
type ItemModel struct { |
|||
ID string |
|||
TRecommended int |
|||
TActed int |
|||
} |
|||
|
|||
var scores []float64 |
|||
var ranking []ItemModel |
@ -0,0 +1,43 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"fmt" |
|||
"io/ioutil" |
|||
"strings" |
|||
|
|||
mgo "gopkg.in/mgo.v2" |
|||
) |
|||
|
|||
func readDataset(path string, lineSeparation string, valueSeparation string) [][]string { |
|||
var dataset [][]string |
|||
b, err := ioutil.ReadFile(path) |
|||
check(err) |
|||
str := string(b) |
|||
str = strings.Replace(str, "\r", "", -1) |
|||
lines := strings.Split(str, lineSeparation) |
|||
for _, v1 := range lines { |
|||
params := strings.Split(v1, valueSeparation) |
|||
var datasetLine []string |
|||
for _, v2 := range params { |
|||
datasetLine = append(datasetLine, v2) |
|||
} |
|||
dataset = append(dataset, datasetLine) |
|||
} |
|||
return dataset |
|||
} |
|||
func getItemsFromDataset(dataset [][]string) []ItemModel { |
|||
var items []ItemModel |
|||
for _, v := range dataset { |
|||
var newItem ItemModel |
|||
newItem.ID = v[0] |
|||
items = append(items, newItem) |
|||
} |
|||
return items |
|||
} |
|||
|
|||
func datasetToMongodbIfNotExist(c *mgo.Collection, items []ItemModel) { |
|||
fmt.Println(items) |
|||
for _, item := range items { |
|||
saveItem(c, item) |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
echo "------------------" |
|||
echo "[Adding new users]" |
|||
|
|||
echo http http://127.0.0.1:3056/user id="user1" age=23 |
|||
http http://127.0.0.1:3056/user id="user1" age=23 |
|||
|
|||
echo http http://127.0.0.1:3056/user id="user2" age=32 |
|||
http http://127.0.0.1:3056/user id="user2" age=32 |
|||
|
|||
echo "------------------" |
|||
|
|||
echo "[Getting recommendations for user]" |
|||
|
|||
echo http http://127.0.0.1:3056/user1/3 |
|||
http http://127.0.0.1:3056/r/user1/3 |