mirror of
https://github.com/crawlab-team/crawlab.git
synced 2026-01-24 17:41:03 +01:00
updated contributors
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"crawlab/constants"
|
||||
"crawlab/database"
|
||||
"github.com/apex/log"
|
||||
"github.com/globalsign/mgo/bson"
|
||||
@@ -82,6 +83,52 @@ func GetActionListTotal(filter interface{}) (int, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func GetVisitDays(uid bson.ObjectId) (int, error) {
|
||||
type ResData struct {
|
||||
Days int `json:"days" bson:"days"`
|
||||
}
|
||||
s, c := database.GetCol("actions")
|
||||
defer s.Close()
|
||||
|
||||
pipeline := []bson.M{
|
||||
{
|
||||
"$match": bson.M{
|
||||
"user_id": uid,
|
||||
"type": constants.ActionTypeVisit,
|
||||
},
|
||||
},
|
||||
{
|
||||
"$addFields": bson.M{
|
||||
"date": bson.M{
|
||||
"$dateToString": bson.M{
|
||||
"format": "%Y%m%d",
|
||||
"date": "$create_ts",
|
||||
"timezone": "Asia/Shanghai",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"$group": bson.M{
|
||||
"_id": "$date",
|
||||
},
|
||||
},
|
||||
{
|
||||
"_id": nil,
|
||||
"days": bson.M{"$sum": 1},
|
||||
},
|
||||
}
|
||||
|
||||
var resData []ResData
|
||||
if err := c.Pipe(pipeline).All(&resData); err != nil {
|
||||
log.Errorf(err.Error())
|
||||
debug.PrintStack()
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return resData[0].Days, nil
|
||||
}
|
||||
|
||||
func UpdateAction(id bson.ObjectId, item Action) error {
|
||||
s, c := database.GetCol("actions")
|
||||
defer s.Close()
|
||||
|
||||
@@ -97,8 +97,28 @@ func GetChallengeList(filter interface{}, skip int, limit int, sortKey string) (
|
||||
return challenges, err
|
||||
}
|
||||
|
||||
//for _, ch := range challenges {
|
||||
//}
|
||||
return challenges, nil
|
||||
}
|
||||
|
||||
func GetChallengeListWithAchieved(filter interface{}, skip int, limit int, sortKey string, uid bson.ObjectId) ([]Challenge, error) {
|
||||
challenges, err := GetChallengeList(filter, skip, limit, sortKey)
|
||||
if err != nil {
|
||||
return challenges, err
|
||||
}
|
||||
|
||||
for i, ch := range challenges {
|
||||
query := bson.M{
|
||||
"user_id": uid,
|
||||
"challenge_id": ch.Id,
|
||||
}
|
||||
|
||||
list, err := GetChallengeAchievementList(query, 0, 1, "-_id")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
challenges[i].Achieved = len(list) > 0
|
||||
}
|
||||
|
||||
return challenges, nil
|
||||
}
|
||||
@@ -152,3 +172,16 @@ func (ca *ChallengeAchievement) Add() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetChallengeAchievementList(filter interface{}, skip int, limit int, sortKey string) ([]ChallengeAchievement, error) {
|
||||
s, c := database.GetCol("challenges_achievements")
|
||||
defer s.Close()
|
||||
|
||||
var challengeAchievements []ChallengeAchievement
|
||||
if err := c.Find(filter).Skip(skip).Limit(limit).Sort(sortKey).All(&challengeAchievements); err != nil {
|
||||
debug.PrintStack()
|
||||
return challengeAchievements, err
|
||||
}
|
||||
|
||||
return challengeAchievements, nil
|
||||
}
|
||||
|
||||
@@ -15,11 +15,12 @@ type Project struct {
|
||||
Description string `json:"description" bson:"description"`
|
||||
Tags []string `json:"tags" bson:"tags"`
|
||||
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
|
||||
// 前端展示
|
||||
Spiders []Spider `json:"spiders" bson:"spiders"`
|
||||
|
||||
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
}
|
||||
|
||||
func (p *Project) Save() error {
|
||||
|
||||
@@ -65,8 +65,9 @@ type Spider struct {
|
||||
LatestTasks []Task `json:"latest_tasks"` // 最近任务列表
|
||||
|
||||
// 时间
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
}
|
||||
|
||||
// 更新爬虫
|
||||
|
||||
@@ -25,14 +25,16 @@ type Task struct {
|
||||
RuntimeDuration float64 `json:"runtime_duration" bson:"runtime_duration"`
|
||||
TotalDuration float64 `json:"total_duration" bson:"total_duration"`
|
||||
Pid int `json:"pid" bson:"pid"`
|
||||
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
|
||||
RunType string `json:"run_type" bson:"run_type"`
|
||||
ScheduleId bson.ObjectId `json:"schedule_id" bson:"schedule_id"`
|
||||
|
||||
// 前端数据
|
||||
SpiderName string `json:"spider_name"`
|
||||
NodeName string `json:"node_name"`
|
||||
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
UserId bson.ObjectId `json:"user_id" bson:"user_id"`
|
||||
CreateTs time.Time `json:"create_ts" bson:"create_ts"`
|
||||
UpdateTs time.Time `json:"update_ts" bson:"update_ts"`
|
||||
}
|
||||
|
||||
type TaskDailyItem struct {
|
||||
|
||||
Reference in New Issue
Block a user