<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 {
	Key string
	/*
		    Current float64
			Expect  float64
			Total   float64
	*/
	TotalSales    float64
	TotalValue    float64
	ChannelSales  map[string]float64
	ChannelValue  map[string]float64
	ExpectedValue map[string]float64
	Ratio         map[string]float64
}

var plallocs = map[string]*plalloc{}

func buildRatio(tn string) error {
	plallocs = map[string]*plalloc{}
	rconn, _ := modules.GetDboxIConnection("db_godrej")
	defer rconn.Close()

	//totalBlanks := map[string]float64{}

	ctrx, e := rconn.NewQuery().From(tn).
		Select().Cursor(nil)
	if e != nil {
		return e
	}
	defer ctrx.Close()
	count := ctrx.Count()
	i := 0
	for {
		mtrx := toolkit.M{}
		if e = ctrx.Fetch(&mtrx, 1, false); e != nil {
			break
		}
		i++
		toolkit.Printfn("Ratio 1: %d of %d in %s",
			i, count, time.Since(t0).String())

		key := mtrx.Get("key", toolkit.M{}).(toolkit.M)
		fiscal := key.GetString("date_fiscal")
		channel := key.GetString("customer_reportchannel")
		sales := mtrx.GetFloat64("PL8A")
		value := mtrx.GetFloat64("PL7A")
		falloc := plallocs[fiscal]
		if falloc == nil {
			falloc = new(plalloc)
			falloc.Ratio = map[string]float64{}
			falloc.ChannelValue = map[string]float64{}
			falloc.ChannelSales = map[string]float64{}
			falloc.ExpectedValue = map[string]float64{}
		}

		falloc.Key = fiscal
		falloc.TotalSales += sales
		falloc.TotalValue += value
		falloc.ChannelSales[channel] = falloc.ChannelSales[channel] + sales
		falloc.ChannelValue[channel] = falloc.ChannelValue[channel] + value
		plallocs[fiscal] = falloc
	}

	for _, falloc := range plallocs {
		for c, _ := range falloc.ChannelSales {
			falloc.Ratio[c] = toolkit.Div(falloc.ChannelSales[c], falloc.TotalSales)
			falloc.ExpectedValue[c] = falloc.Ratio[c] * falloc.TotalValue
		}
	}
<commit_msg>apply onluy for mt.gt.rd<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 {
	Key string
	/*
		    Current float64
			Expect  float64
			Total   float64
	*/
	TotalSales    float64
	TotalValue    float64
	ChannelSales  map[string]float64
	ChannelValue  map[string]float64
	ExpectedValue map[string]float64
	Ratio         map[string]float64
}

var plallocs = map[string]*plalloc{}

func buildRatio(tn string) error {
	plallocs = map[string]*plalloc{}
	rconn, _ := modules.GetDboxIConnection("db_godrej")
	defer rconn.Close()

	//totalBlanks := map[string]float64{}

	ctrx, e := rconn.NewQuery().From(tn).
		Select().Cursor(nil)
	if e != nil {
		return e
	}
	defer ctrx.Close()
	count := ctrx.Count()
	i := 0
	for {
		mtrx := toolkit.M{}
		if e = ctrx.Fetch(&mtrx, 1, false); e != nil {
			break
		}
		i++
		toolkit.Printfn("Ratio 1: %d of %d in %s",
			i, count, time.Since(t0).String())

		key := mtrx.Get("key", toolkit.M{}).(toolkit.M)
		fiscal := key.GetString("date_fiscal")
		channel := key.GetString("customer_reportchannel")
		sales := mtrx.GetFloat64("PL8A")
		value := mtrx.GetFloat64("PL7A")
		if toolkit.HasMember([]string{"GT", "MT", "RD"}, channel) {
			falloc := plallocs[fiscal]
			if falloc == nil {
				falloc = new(plalloc)
				falloc.Ratio = map[string]float64{}
				falloc.ChannelValue = map[string]float64{}
				falloc.ChannelSales = map[string]float64{}
				falloc.ExpectedValue = map[string]float64{}
			}

			falloc.Key = fiscal
			falloc.TotalSales += sales
			falloc.TotalValue += value
			falloc.ChannelSales[channel] = falloc.ChannelSales[channel] + sales
			falloc.ChannelValue[channel] = falloc.ChannelValue[channel] + value
			plallocs[fiscal] = falloc
		}
	}

	for _, falloc := range plallocs {
		for c, _ := range falloc.ChannelSales {
			falloc.Ratio[c] = toolkit.Div(falloc.ChannelSales[c], falloc.TotalSales)
			falloc.ExpectedValue[c] = falloc.Ratio[c] * falloc.TotalValue
		}
	}

{'fraction_non_alphanumeric': 0.1392429888213375, 'fraction_numerical': 0.0172582859384193, 'mean_word_length': 3.3889845094664373, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7362172', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1928, 'n_words': 374}