Пример #1
0
func readOutput(outputPath string) []Report {
	reports := make([]Report, 0)
	file, _ := xlsx.OpenFile(outputPath)

	startIndexes := make(map[string]int)

	for sheetIndex, sheet := range file.Sheets {
		if sheetIndex != 2 {
			continue
		}

		var companyStarted bool = false
		var companyReport Report
		datesSet := set.NewNonTS()
		var datesIndexes map[int]string

		for rowIndex, row := range sheet.Rows {

			var status string

			for cellIndex, cell := range row.Cells {
				if cell.Value == "" {
					continue
				}
				if strings.Contains(strings.ToLower(cell.String()), "результат") {
					startIndexes[sheet.Cell(rowIndex-1, cellIndex).String()] = rowIndex - 1

					companyStarted = true

					companyReport = Report{}
					companyReport.Company = sheet.Cell(rowIndex-1, cellIndex).String()
					companyReport.StartRow = rowIndex - 1
					companyReport.StartLeftOffset = cellIndex
					companyReport.Results = make(map[string]map[string]int)
					fmt.Println("Started ", sheet.Cell(rowIndex-1, cellIndex).String())

					datesIndexes = make(map[int]string)

					continue
				}
				if strings.Contains(strings.ToLower(cell.String()), "общий") {
					continue
				}
				if companyStarted {
					if rowIndex == companyReport.StartRow+1 {
						datesIndexes[cellIndex] = strings.Replace(cell.String(), "-", "/", -1)
						//												fmt.Println(strings.Replace(cell.String(), "-", "/", -1))
						datesSet.Add(strings.Replace(cell.String(), "-", "/", -1))
						companyReport.Results[strings.Replace(cell.String(), "-", "/", -1)] = make(map[string]int)
					} else {
						if strings.Contains(strings.ToLower(cell.String()), "всего") {
							companyStarted = false

							/*for date, statusMap := range companyReport.Results {
								for status, value := range statusMap {
									fmt.Println(date, ":", status, ":", value)
								}
							}*/
							reports = append(reports, companyReport)

						} else {
							if cellIndex == companyReport.StartLeftOffset {
								status = cell.String()
							} else if cellIndex == companyReport.StartLeftOffset+1 {
								//общий
								continue
							} else {
								intValue, _ := cell.Int()
								companyReport.Results[datesIndexes[cellIndex]][status] += intValue
							}
						}
					}
				}
				//				fmt.Printf("%s ", cell.String())
			}
			//			fmt.Println()
		}
	}

	/*for company, startIndex := range startIndexes {
		fmt.Printf("%s: %v\n", company, startIndex)
	}*/
	return reports
}
Пример #2
0
func readInputFile(filePath string) Report {
	fileName := getFileNameFromPath(filePath, true)

	inputFile, err := xlsx.OpenFile(filePath)
	if err != nil {
	}

	//[date][status]
	statuses := make(map[string]map[string]int)

	var dateIndex int
	var statusIndex int

	for sheetIndex, sheet := range inputFile.Sheets {
		if sheetIndex != 0 {
			continue
		}

		for rowIndex, row := range sheet.Rows {
			if rowIndex == 0 {
				for cellIndex, cell := range row.Cells {
					lowerCell := strings.ToLower(cell.String())
					if strings.Contains(lowerCell, "статус") || strings.Contains(lowerCell, "согласие") {
						statusIndex = cellIndex
					} else if strings.Contains(lowerCell, "дата") {
						dateIndex = cellIndex
					}
				}
			} else {
				var date string
				var status string

				for cellIndex, cell := range row.Cells {
					if cellIndex == dateIndex {
						//						date, _ := time.Parse("02/01/2006 15:04", cell.String())
						//						dateString := fmt.Sprintf("%v_%s", date.Day(), date.Month())
						dateTime := strings.Split(cell.String(), " ")
						if len(dateTime) > 0 {
							date = dateTime[0]
						}
					} else if cellIndex == statusIndex {
						status = cell.String()
						//statuses[cell.String()]++;
					}
				}
				if date != "" && status != "" {
					//					fmt.Printf("%s\n", date)
					//					fmt.Printf("%s\n", status)

					dateMap, ok := statuses[date]
					if !ok || dateMap == nil {
						//						fmt.Println("created for", date)
						dateMap = make(map[string]int)
						statuses[date] = dateMap
					}
					statuses[date][status]++
				}
			}
		}
	}
	return Report{Company: fileName, Results: statuses}
}