summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Gotsche <n@softwarefools.com>2019-05-08 01:08:42 +0200
committerNikolaus Gotsche <n@softwarefools.com>2019-05-08 01:08:42 +0200
commit1308154bfde61973308df8e908a45cd95781939c (patch)
tree2a809eab566ad216af1f83d456fb161cbcc2af20
parent8e7dec5dd1b4be5fd752acd6468d0cd801501e1f (diff)
More Analysis - still test
-rw-r--r--analyze.go115
-rw-r--r--interact.go12
-rw-r--r--sqlite.go45
3 files changed, 162 insertions, 10 deletions
diff --git a/analyze.go b/analyze.go
new file mode 100644
index 0000000..86a18c8
--- /dev/null
+++ b/analyze.go
@@ -0,0 +1,115 @@
+// analyze.go contains all data analysis
+package main
+
+import (
+ "fmt"
+)
+
+// Data for Month
+type Month struct {
+ Month int
+ MonthName string
+ Year int
+ Days []int
+
+ Earnings float64
+
+ Workhours float64
+ //Workdays int
+ Tasks []int
+ Projects []int
+}
+
+var analysis []Month
+
+
+//Analyze all tasks and PAyments
+func MakeAnalysis() {
+ fmt.Println("Making Analysis")
+
+ tids := GetTaskIds()
+ alltasks := GetSelectedTasks(tids)
+
+ for _,ta := range alltasks {
+ year,monthn,day := ta.Start.Local().Date()
+ month := int(monthn)
+ monthstr := fmt.Sprintf("%v",monthn)
+ exist, exid := MonthExists(year,month)
+ dur := ta.Duration()
+
+ if exist {
+ if !isElement(day,analysis[exid].Days){
+ analysis[exid].Days = append(analysis[exid].Days,day)
+ }
+ analysis[exid].Workhours += dur
+ analysis[exid].Tasks = append(analysis[exid].Tasks,ta.Id)
+ if !isElement(ta.Projectid,analysis[exid].Projects){
+ analysis[exid].Projects = append(analysis[exid].Projects,ta.Projectid)
+ }
+ }else{
+ analysis = append(analysis,Month{
+ month,
+ monthstr,
+ year,
+ []int{day},
+
+ 0.0, //Earning
+
+ dur, //Workhours
+ []int{ta.Id},[]int{ta.Projectid}})
+ }
+
+ }
+ pays := GetAllPayments()
+ for _,py := range pays {
+ year,monthn,_ := py.Date.Local().Date()
+ month := int(monthn)
+ monthstr := fmt.Sprintf("%v",monthn)
+ exist, exid := MonthExists(year,month)
+
+ if exist {
+ analysis[exid].Earnings += py.Amount
+ }else{
+ analysis = append(analysis,Month{
+ month,
+ monthstr,
+ year,
+ []int{},
+
+ py.Amount, //Earning
+
+ 0.0, //Workhours
+ []int{},
+ []int{}})
+ }
+ }
+ //fmt.Println("Length:",len(analysis))
+ ShowFullAnalysis()
+}
+
+
+//Show full analysis
+func ShowFullAnalysis() {
+ fmt.Println(frame("Full Analysis",true))
+ for _,mo := range analysis {
+ fmt.Println(sli,mo.Year,mo.MonthName)
+ fmt.Printf("%s Workhours: %.2f\n",nli,mo.Workhours)
+ fmt.Println(nli," Days:",mo.Days)
+ cnt, hr, dur := AnalyzeTasks(GetSelectedTasks(mo.Tasks))
+ fmt.Println(nli," Tasks:",cnt,"Hours:", hr)
+ fmt.Println(nli,dur)
+ fmt.Println(nli,"Projects:",len(mo.Projects))
+ }
+ fmt.Println(frame("",false))
+}
+
+
+// Test if analysis slice conatins the month already and return its id if
+func MonthExists(year, month int) (exist bool, id int) {
+ for i,mo := range analysis {
+ if mo.Month == month && mo.Year == year {
+ return true,i
+ }
+ }
+ return false,-1
+}
diff --git a/interact.go b/interact.go
index a03a672..ab5a950 100644
--- a/interact.go
+++ b/interact.go
@@ -230,16 +230,11 @@ func interact(fulldb bool) {
c.Println(boldRed(arg, " is not a valid id!"))
}
} else {
- /*
- tids := GetTaskIds()
- selids, lids := GetPaymentList(tids, false,false)
- choice := c.MultiChoice(lids, "Select a Task to Edit")
+ selids, lids := GetPaymentList()
+ choice := c.MultiChoice(lids, "Select a Payment to Edit")
if choice > -1 {
- deleteTask(selids[choice])
+ DeletePayment(selids[choice])
}
- */
- //c.Println(boldRed("deletetask <id> - Please enter an id"))
- //allProjects()
}
c.Println(promptcol("______________________"))
},
@@ -793,6 +788,7 @@ func interact(fulldb bool) {
Test Export`,
Func: func(c *ishell.Context) {
c.Println("Said new!!!")
+ MakeAnalysis()
//getInterAutoInput("Really?",autostuff)
},
})
diff --git a/sqlite.go b/sqlite.go
index c24aae6..1c92a17 100644
--- a/sqlite.go
+++ b/sqlite.go
@@ -81,6 +81,17 @@ type IdMap struct {
New int
}
+// Methods
+
+func (t Task) Duration() float64 {
+ dur := t.Stop.Sub(t.Start)
+ return dur.Hours()
+}
+
+
+
+// Global Variables
+
var db *sql.DB
var err error
var currproject Project
@@ -823,7 +834,7 @@ func closeTask(loud bool) {
}
}
-// TODO Make an uncheck function
+// Mark bill as paid, connect it to payment
func checkBill(billid, payid, projectid int, datestr string) {
//boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
@@ -1334,6 +1345,27 @@ func GetAllBills() (out []bill) {
return
}
+
+// Returns Slice of All Payments
+func GetAllPayments() (out []Payment) {
+ //var ids []int
+ rows, err := db.Query("SELECT * FROM payments") // ORDER BY id DESC")
+ checkErr(err)
+ var id,cuid int
+ var amt float64
+ var dat time.Time
+ var bistr string
+ var bi []int
+ defer rows.Close()
+ for rows.Next() {
+ err = rows.Scan(&id,&cuid,&amt,&bistr,&dat)
+ checkErr(err)
+ bi = String2IntArray(bistr,";")
+ out = append(out,Payment{id,cuid,amt,dat,bi})
+ }
+ return
+}
+
// Get All Tasks of Project with prid as a slice of Tasknames and
// a curresponding slice of strings to display
func GetTaskSums(prid int) (names,strings []string ) {
@@ -1487,7 +1519,6 @@ func showOpenProject(alone bool) {
// Unser Input to create a new Payment
func AddPayment(dat string) {
- //TODO
boldRed := color.New(color.FgRed, color.Bold).SprintFunc()
boldGreen := color.New(color.FgGreen, color.Bold).SprintFunc()
const form = "2006-01-02"
@@ -1815,6 +1846,8 @@ func setProject(nid int) {
showCurrentTask()
}
+
+// GEt String Slice and corresponding Id Slice for Multicoice selection
func GetPaymentList() (outint []int, outstr []string) {
rows, err := db.Query("SELECT id, customerid, amount, bills, date FROM payments")
checkErr(err)
@@ -1827,6 +1860,14 @@ func GetPaymentList() (outint []int, outstr []string) {
err = rows.Scan(&id, &cuid, &amt, &bills, &dat)
checkErr(err)
cun := getCustomerName(cuid)
+// biids := String2IntArray(bills,";")
+// mybills := loadBills(biids)
+/*
+ bsum := 0.0
+ hsum := 0.0
+ for _,bi := range mybills{
+
+ } */
st := fmt.Sprintf("%v: (%s) %s : %.2f[€] - Bills: %s",id, dat.Local().Format("2006-01-02"),cun, amt,bills)
outint = append(outint, id)
outstr = append(outstr, st)