Example #1
0
// GetProgramAnalysersByProgram gets all the program analysers for a program
func GetProgramAnalysersByProgram(programID int) []ProgramAnalyser {
	var list []ProgramAnalyser
	fieldList := "`id`, `description`, `formats`, `keywords`, `analyse`"
	sql := "SELECT " + fieldList + " FROM `digest_program` WHERE program=? "
	rows, _ := database.Connection.Query(sql, programID)
	for rows.Next() {
		var d1, d2, d3 string
		analyser := ProgramAnalyser{}
		rows.Scan(&analyser.id, &d1, &d2, &d3, &analyser.parentID)
		analyser.description = word.NewDigesterFromJSON(d1)
		analyser.formats = word.NewDigesterFromJSON(d2)
		analyser.keywords = word.NewDigesterFromJSON(d3)
		list = append(list, analyser)
	}
	return list
}
Example #2
0
func (analyser *InstitutionAnalyser) perform() {

	institution := analyser.institution

	subjects := education.GetAllSubjects()

	for _, subject := range subjects {
		exists := false
		programs := institution.GetProgramsBySubjectID(subject.GetID())

		keywords := word.NewDigester("")
		formats := word.NewDigester("")
		description := word.NewDigester("")

		for _, program := range programs {
			exists = true
			fieldList := "`description`, `formats`, `keywords`"
			sql := "SELECT " + fieldList + " FROM `digest_program` WHERE program=? AND analyse=? "
			rows, _ := database.Connection.Query(sql, program.GetID(), analyser.parent.id)
			for rows.Next() {
				var s1, s2, s3 string
				rows.Scan(&s1, &s2, &s3)
				description = description.Combine(word.NewDigesterFromJSON(s1))
				formats = formats.Combine(word.NewDigesterFromJSON(s2))
				keywords = keywords.Combine(word.NewDigesterFromJSON(s3))
			}
		}
		if exists {
			keywords.SortByCounter("DESC")
			description.SortByCounter("DESC")
			formats.SortByCounter("DESC")

			columns := "`institution`, `subject`, `description`, `formats`, `keywords`, `analyse`"
			table := "digest_institution"

			buffer := database.NewSQLBuffer(table, columns)
			buffer.AddRow(institution.ID, subject.GetID(), description.GetPlainJSON(), formats.GetPlainJSON(), keywords.GetPlainJSON(), analyser.parent.id)

			err := buffer.Exec()

			if err != nil {
				fmt.Println(err)
			}
		}
	}
}
Example #3
0
// GetInstitutionAnalysersByInstitution gets all the analyses for the institution
func GetInstitutionAnalysersByInstitution(institutionID int) []InstitutionAnalyser {
	var list []InstitutionAnalyser
	fieldList := "`id`, `description`, `formats`, `keywords`, `analyse`, `subject`"
	sql := "SELECT " + fieldList + " FROM `digest_institution` WHERE institution=? ORDER by analyse DESC"
	rows, err := database.Connection.Query(sql, institutionID)
	if err != nil {
		fmt.Println(err)
	}
	for rows.Next() {
		var d1, d2, d3 string
		analyser := InstitutionAnalyser{}
		rows.Scan(&analyser.id, &d1, &d2, &d3, &analyser.parentID, &analyser.subject)
		analyser.description = word.NewDigesterFromJSON(d1)
		analyser.formats = word.NewDigesterFromJSON(d2)
		analyser.keywords = word.NewDigesterFromJSON(d3)
		fmt.Println(analyser.GetParent())
		list = append(list, analyser)
	}
	return list
}
Example #4
0
func (analyser ProgramAnalyser) getDigesters(module repository.Module) (*word.Digester, *word.Digester, *word.Digester) {

	fieldList := "`keywords`, `formats`, `description`"
	sql := "SELECT " + fieldList + " FROM `digest_module` WHERE module=? AND analyse=? LIMIT 0,1"
	rows, err := database.Connection.Query(sql, module.GetID(), analyser.parent.parent.id)

	if err != nil {
		panic(err)
	}

	keywords := word.NewDigester("")
	formats := word.NewDigester("")
	description := word.NewDigester("")

	for rows.Next() {
		var d1, d2, d3 string
		rows.Scan(&d1, &d2, &d3)
		keywords = word.NewDigesterFromJSON(d1)
		formats = word.NewDigesterFromJSON(d2)
		description = word.NewDigesterFromJSON(d3)
	}
	return keywords, formats, description
}
Example #5
0
func (analyser SubjectAnalyser) getDigesters(institution repository.Institution) (*word.Digester, *word.Digester, *word.Digester) {
	subject := analyser.subject
	fieldList := "`keywords`, `formats`, `description`"
	sql := "SELECT " + fieldList + " FROM `digest_institution` WHERE institution=? AND analyse=? AND subject = ? LIMIT 0,1"
	rows, err := database.Connection.Query(sql, institution.ID, analyser.parent.id, subject.GetID())

	if err != nil {
		panic(err)
	}

	keywords := word.NewDigester("")
	formats := word.NewDigester("")
	description := word.NewDigester("")

	for rows.Next() {
		var d1, d2, d3 string
		rows.Scan(&d1, &d2, &d3)
		keywords = word.NewDigesterFromJSON(d1)
		formats = word.NewDigesterFromJSON(d2)
		description = word.NewDigesterFromJSON(d3)
	}
	return keywords, formats, description
}