<commit_before>package main

import (
	"eaciit/gdrj/model"
	"eaciit/gdrj/modules"
	"os"

	"github.com/eaciit/dbox"
	"github.com/eaciit/orm/v1"
	"github.com/eaciit/toolkit"
	// "strings"
	"time"
)

var conn dbox.IConnection
var count int

var (
	t0                          time.Time
	fiscalyear, iscount, scount int
	data                        map[string]float64
	masters                     = toolkit.M{}
)

func setinitialconnection() {
	var err error
	conn, err = modules.GetDboxIConnection("db_godrej")

	if err != nil {
		toolkit.Println("Initial connection found : ", err)
		os.Exit(1)
	}

	err = gdrj.SetDb(conn)
	if err != nil {
		toolkit.Println("Initial connection found : ", err)
		os.Exit(1)
	}
}

type plalloc struct {
	ChannelID                                    string
	TotalNow, TotalExpect, RatioNow, RatioExpect float64
	TotalSales                                   float64
}

func (s *plalloc) Multiplier() float64 {
	if s.RatioNow == 0 {
		return 0
	}
	return s.RatioExpect / s.RatioNow
}

func calcDiff(tablename string) (m map[string]map[string]*plalloc, err error) {
	diffConn, _ := modules.GetDboxIConnection("db_godrej")
	defer diffConn.Close()

	m = map[string]map[string]*plalloc{}
	totalplvs := map[string]float64{}
	totalsaless := map[string]float64{}
	sumnow, _ := diffConn.NewQuery().From(tablename).
		Cursor(nil)
	count := sumnow.Count()
	i := 0
	for {
		mnow := toolkit.M{}
		efetch := sumnow.Fetch(&mnow, 1, false)
		if efetch != nil {
			break
		}
		i++
		toolkit.Printfn("Calculating diff. %d of %d in %s",
			i, count, time.Since(t0).String())

		key := mnow.Get("key", toolkit.M{}).(toolkit.M)
		fiscal := key.GetString("date_fiscal")
		sgaf, sgafExist := m[fiscal]
		totalplv := totalplvs[fiscal]
		totalsales := totalsaless[fiscal]
		if !sgafExist {
			sgaf = map[string]*plalloc{}
			m[fiscal] = sgaf
		}

		channelid := key.GetString("customer_channelid")
		if channelid != "EXP" {
			sga, sgaExist := sgaf[channelid]
			if !sgaExist {
				sga = new(plalloc)
				sgaf[channelid] = sga
			}
			pla.ChannelID = channelid
			plvalue := mnow.GetFloat64("PL23")
			pla.TotalNow += plvalue
			salesvalue := mnow.GetFloat64("PL8A")
			pla.TotalSales += salesvalue
			totalplv += plvalue
			totalsales += salesvalue<commit_msg>upda freih<commit_after>package main

import (
	"eaciit/gdrj/model"
	"eaciit/gdrj/modules"
	"os"

	"github.com/eaciit/dbox"
	"github.com/eaciit/orm/v1"
	"github.com/eaciit/toolkit"
	// "strings"
	"time"
)

var conn dbox.IConnection
var count int

var (
	t0                          time.Time
	fiscalyear, iscount, scount int
	data                        map[string]float64
	masters                     = toolkit.M{}
)

func setinitialconnection() {
	var err error
	conn, err = modules.GetDboxIConnection("db_godrej")

	if err != nil {
		toolkit.Println("Initial connection found : ", err)
		os.Exit(1)
	}

	err = gdrj.SetDb(conn)
	if err != nil {
		toolkit.Println("Initial connection found : ", err)
		os.Exit(1)
	}
}

type plalloc struct {
	ChannelID                                    string
	TotalNow, TotalExpect, RatioNow, RatioExpect float64
	TotalSales                                   float64
}

func (s *plalloc) Multiplier() float64 {
	if s.RatioNow == 0 {
		return 0
	}
	return s.RatioExpect / s.RatioNow
}

func calcDiff(tablename string) (m map[string]map[string]*plalloc, err error) {
	diffConn, _ := modules.GetDboxIConnection("db_godrej")
	defer diffConn.Close()

	m = map[string]map[string]*plalloc{}
	totalplvs := map[string]float64{}
	totalsaless := map[string]float64{}
	sumnow, _ := diffConn.NewQuery().From(tablename).
		Cursor(nil)
	count := sumnow.Count()
	i := 0
	for {
		mnow := toolkit.M{}
		efetch := sumnow.Fetch(&mnow, 1, false)
		if efetch != nil {
			break
		}
		i++
		toolkit.Printfn("Calculating diff. %d of %d in %s",
			i, count, time.Since(t0).String())

		key := mnow.Get("key", toolkit.M{}).(toolkit.M)
		fiscal := key.GetString("date_fiscal")
		plaf, plafExist := m[fiscal]
		totalplv := totalplvs[fiscal]
		totalsales := totalsaless[fiscal]
		if !plafExist {
			plaf = map[string]*plalloc{}
			m[fiscal] = plaf
		}

		channelid := key.GetString("customer_channelid")
		if channelid != "EXP" {
			pla, plaExist := sgaf[channelid]
			if !plaExist {
				pla = new(plalloc)
				plaf[channelid] = pla
			}
			pla.ChannelID = channelid
			plvalue := mnow.GetFloat64("PL23")
			pla.TotalNow += plvalue
			salesvalue := mnow.GetFloat64("PL8A")
			pla.TotalSales += salesvalue
			totalplv += plvalue
			totalsales += salesvalue
{'fraction_non_alphanumeric': 0.13701657458563535, 'fraction_numerical': 0.012375690607734807, 'mean_word_length': 2.9911816578483243, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4481515', 'n_tokens_mistral': 1892, 'n_tokens_neox': 1717, 'n_words': 342}