⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dmreporter.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
end

function DMReporter_OuptutClassReportCSV(outputFilename)
	-- Open the file.
	outputFileHandle = io.open(outputFilename, "w+");
	if (nil == outputFileHandle) then
		io.write("Error opening "..outputFilename);
		return;
	end
	io.write("(CSV Class Report) Reporting to "..outputFilename.."...\n");

	--------------------

	local classTable = {};

	local ix;
	local class, classInfo;
	for ix = 1, table.getn(DamageMeters_tables[DMT_ACTIVE]) do
		local playerInfo = DamageMeters_tables[DMT_ACTIVE][ix];
		if (playerInfo.class and playerInfo.class ~= "") then
			class = DamageMeters_tables[DMT_ACTIVE][ix].class;
			if (classTable[class] == nil) then
				classTable[class] = {};
				classTable[class].count = 0;
				classTable[class].quants = {0, 0, 0, 0};
			end
			classTable[class].count = classTable[class].count + 1;

			local quant;
			for quant = 1, DMI_REPORT_MAX do
				classTable[class].quants[quant] = classTable[class].quants[quant] + playerInfo.dmiData[quant].q;
			end
		end
	end


	-- Generate header string.
	local msg, quant;
	msg = "Class,Count";
	for quant = 1, DMI_REPORT_MAX do
		msg = msg..","..DM_QUANTDEFS[quant].name..",Avg "..DM_QUANTDEFS[quant].name;
	end
	DamageMeters_SendReportMsg(msg);

	for class, classInfo in classTable do
		local msg = string.format("%s,%d,%d,%d,%d,%d,%d,%d,%d,%d", class, classInfo.count, 
		classInfo.quants[1], DM_GetFraction(classInfo.quants[1],classInfo.count), 
		classInfo.quants[2], DM_GetFraction(classInfo.quants[2],classInfo.count), 
		classInfo.quants[3], DM_GetFraction(classInfo.quants[3],classInfo.count), 
		classInfo.quants[4], DM_GetFraction(classInfo.quants[4],classInfo.count));
		DamageMeters_SendReportMsg(msg);
	end

	-- Close the file.
	outputFileHandle:close();
end

function DMReporter_OutputPercentagesReportCSV(outputFilename)
	-- Open the file.
	outputFileHandle = io.open(outputFilename, "w+");
	if (nil == outputFileHandle) then
		io.write("Error opening "..outputFilename);
		return;
	end
	io.write("(CSV Class Report) Reporting to "..outputFilename.."...\n");

	--------------------

	local msg = "Player,Class"
	for ii = 1, DMI_REPORT_MAX do
		msg = string.format("%s,%s,Pct Of Total,Pct Of Leader",
			msg, DM_QUANTDEFS[ii].name);
	end
	DamageMeters_SendReportMsg(msg);

	-- Calculate totals.
	local index;
	local info;
	local totals = {0, 0, 0, 0, 0, 0};
	local peaks = {0, 0, 0, 0};
	for index,info in DamageMeters_tables[DMT_ACTIVE] do 
		local ii;
		for ii = 1, DMI_REPORT_MAX do
			msg = string.format(",%s,%s,Pct Of Total,Pct Of Leader",
				msg, DM_QUANTDEFS[ii].name);
			totals[ii] = totals[ii] + info.dmiData[ii].q;
			if (info.dmiData[ii].q > peaks[ii]) then
				peaks[ii] = info.dmiData[ii].q;
			end
		end
		totals[5] = totals[5] + info.dmiData[DMI_DAMAGE].hitCount;
		totals[6] = totals[6] + info.dmiData[DMI_DAMAGE].critCount;
	end
	DamageMeters_DetermineRanks(DMT_ACTIVE);

	for index = 1, table.getn(DamageMeters_tables[DMT_ACTIVE]) do
		local struct = DamageMeters_tables[DMT_ACTIVE][index];

		local class = struct.class and struct.class or "";
		msg = string.format("%s,%s", struct.player, class);

		for quant = 1, DMI_REPORT_MAX do
			local percentOfTotal = 100 * DM_GetFraction(struct.dmiData[quant].q, totals[quant]);
			local percentOfLeader = 100 * DM_GetFraction(struct.dmiData[quant].q, peaks[quant]);

			msg = string.format("%s,%d,%.2f,%.2f", 
				msg, struct.dmiData[quant].q, percentOfTotal, percentOfLeader);
		end
		DamageMeters_SendReportMsg(msg);
	end

	-- Close the file.
	outputFileHandle:close();
end

------------------------------------------------------------------------
-- REPORT CODE GOES HERE --
------------------------------------------------------------------------

	-- See if we are using the "saved" (memory) table, rather than the main table.
	if (useSavedTable) then
		io.write("Using Saved Table: Switching active index from "..DMT_ACTIVE.." to ");
		DMT_ACTIVE = (DMT_ACTIVE == DM_TABLE_B) and DM_TABLE_A or DM_TABLE_B;
		io.write(DMT_ACTIVE.."\n");
	end

	-- Sort functions use the visible table, so make sure it refers
	-- to the active table, not the fight table.
	DMT_VISIBLE = DMT_ACTIVE;

	-- Update DMI_MAX to reflect plugin data.
	for plugin, dmi in DamageMeters_pluginDMITable do
		if (dmi > DMI_MAX) then
			DMI_NAMES[dmi] = plugin;
			DMI_MAX = dmi;
		end
	end

	-- Verify that the table has data.
	if (nil == DamageMeters_tables[DMT_ACTIVE] or 0 == table.getn(DamageMeters_tables[DMT_ACTIVE])) then
		io.write("Table is empty.");
		return;
	end

	local filenameList = {};
	local sessionLabel = "";
	if (useSessionLabel) then
		if (DamageMeters_tableInfo[DMT_VISIBLE].sessionLabel) then
			sessionLabel = "_"..DamageMeters_tableInfo[DMT_VISIBLE].sessionLabel;
		end
	end

	-- Build a string which contains the current date and time so that we can 
	-- uniquely name our report files.
	local dateTimeString = "";
	if (useDateStamp or useTimeStamp) then
		local dateTable = os.date("*t");
		if (useDateStamp) then
			dateTimeString = string.format("_%d%02d%02d", dateTable.year, dateTable.month, dateTable.day);
		end
		if (useTimeStamp) then
			dateTimeString = dateTimeString..string.format("_%02d%02d%02d", dateTable.hour, dateTable.min, dateTable.sec);
		end
	end

	local fullSuffix = dateTimeString..sessionLabel..filenameSuffix;

	if (doTotalReport or doLeaderReport or doEventReport) then

		-- Open a file for writing to.
		outputFilename = outputFilenameBase..fullSuffix..".txt";
		outputFileHandle = io.open(outputFilename, "w+");
		if (nil == outputFileHandle) then
			io.write("Error opening "..outputFilename);
			return;
		end
		table.insert(filenameList, outputFilename);
		io.write("Writing report to "..outputFilename.."...\n");

		----------------

		-- Total Report:
		if (doTotalReport) then
			DamageMeters_DoReport(DamageMeters_ReportQuantity_Total, "BUFFER", false, 1, table.getn(DamageMeters_tables[DMT_ACTIVE]), nil);
			DamageMeters_SendReportMsg("\n");
		end

		-- Leader Report:
		if (doLeaderReport) then
			DamageMeters_DoReport(DamageMeters_ReportQuantity_Leaders, "BUFFER", false, 1, table.getn(DamageMeters_tables[DMT_ACTIVE]), nil);
			DamageMeters_SendReportMsg("\n");
		end

		-- Event Report:
		if (doEventReport) then
			DamageMeters_DoReport(DamageMeters_ReportQuantity_Events, "BUFFER", false, 1, table.getn(DamageMeters_tables[DMT_ACTIVE]), nil);
			DamageMeters_SendReportMsg("\n");
		end

		-- Close the file.
		outputFileHandle:close();
	end

	-- Dump table to a CSV file.
	if (createCSVFile) then
		outputFilename = outputFilenameBase..fullSuffix..".csv";
		table.insert(filenameList, outputFilename);
		DMReporter_OutputToCSV(outputFilename);
	end

	-- Dump event table to a CSV file.
	if (createCSVEventFile) then
		outputFilename = outputFilenameBase.."_Events"..fullSuffix..".csv";
		table.insert(filenameList, outputFilename);
		DMReporter_OutputEventsToCSV(outputFilename);
	end

	-- Dump Class Info to a CSV file.
	if (createClassCSVFile) then
		outputFilename = outputFilenameBase.."_Class"..fullSuffix..".csv";
		table.insert(filenameList, outputFilename);
		DMReporter_OuptutClassReportCSV(outputFilename);
	end

	-- Dump Percentage Info to a CSV file
	if (createPercentagesCSVFile) then
		outputFilename = outputFilenameBase.."_Percentages"..fullSuffix..".csv";
		table.insert(filenameList, outputFilename);
		DMReporter_OutputPercentagesReportCSV(outputFilename);
	end

	-- Dump event-totals to a CSV file.
	if (createEventTotalsCSVFile) then
		outputFilename = outputFilenameBase.."_EventTotals"..fullSuffix..".csv";
		table.insert(filenameList, outputFilename);
		DMReporter_OutputEventsTotalsCSV(outputFilename);
	end


	---------------------------------

	if (createWinrarArchive) then
		local archiveName = outputFilenameBase..fullSuffix..".zip";
		local commandLine = "start winrar.exe a -df -- "..archiveName;
		for index, filename in filenameList do
			commandLine = commandLine.." "..filename;
		end
		io.write("Creating archive using command line:\n");
		io.write(commandLine.."\n");
		os.execute(commandLine);
	end

	---------------------------------

	if (nil ~= DM_eventCaseTableDebug) then
		outputFileHandle = io.open("DM_eventCaseTableDebug.txt", "w+");

		outputFileHandle:write("Unparsed Messages in EventCaseTable:\n");
		for msgType, msgTable in DM_eventCaseTableDebug do
			outputFileHandle:write("  "..msgType.."\n");
			for event, eventTable in msgTable do
				--DM_DUMP_TABLE(eventTable);
				
				outputFileHandle:write("    "..event.." ("..eventTable.parseCount.."/"..eventTable.hitCount..")\n");
				for caseIndex, case in eventTable do
					if (type(caseIndex) == "number") then
						outputFileHandle:write("      "..case.n.." ("..case.hitCount..")\n");
						if (nil ~= case.parsed) then
							for parseIx, parse in case.parsed do
								outputFileHandle:write("        "..parse.."\n");
							end
						end
					end
				end

				if (eventTable.unparsed ~= nil) then
					outputFileHandle:write("      [Unparsed]:\n");
					for index, message in eventTable.unparsed do
						outputFileHandle:write("        "..message.."\n");
					end
				end
			end
		end

		io.close(outputFileHandle);
	end

	---------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -