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

📄 dmreporter.lua

📁 时间太紧了
💻 LUA
📖 第 1 页 / 共 2 页
字号:
--[[------------------------------------------------------------------------
DMREPORTER.LUA

This file is designed to be executed by a Lua interpreter.  For security 
reasons, no executable is included with this package.  However, Lua 
executables are freely available on the interweb for all platforms that
WoW runs on:

http://lua-users.org/wiki/LuaBinaries

For example, on Windows you need to put Lua.exe into the DamageMeters 
directory (or in the path, etc), go to the DamageMeters directory 
in a console window, and enter:

lua.exe DMReporter.lua

----

As delivered, this file will create .txt and .csv files with various
reports based upon the data saved in your SavedVariables.lua file.  
There is nothing hidden here, so if you desire a particular type of report 
not included here and aren't afraid of a little Lua programming, why
not give it a shot?

The Basics:
- You have access to the data: DamageMeters_tables.
- You can call some of the report functions that the mod uses, ie. DamageMeters_DoReport.
- If you choose to use the built-in report functions, not that they will 
call the function DamageMeters_SendReportMsg, located in this file.
- You have access to everything in in Localization.lua.

------------------------------------------------------------------------]]--
------------------------------------------------------------------------

-------------
-- OPTIONS --
-------------

-- For convenience the following options below can be toggled to control
-- the output.

if (nil == useSavedTable) then
--useSavedTable = true;				-- Whether or not to use the main or memory table.
end

outputFilenameBase = "DMReport";	-- The base filename for all generated files.
--useTimeStamp = true;				-- Adds date and time to the filename.
useDateStamp = true;				-- Adds date and time to the filename.
useSessionLabel = true;				-- Adds the name of the session to the filename.
filenameSuffix = ""					-- Added to the end of the filename.

doTotalReport = true;				-- Outputs a list of total values for each player.
doLeaderReport = true;  			-- Outputs lists of the leading players for each value.
doEventReport = true;				-- For this to be meaningful, you need to run with event data collection.
createCSVFile = true;				-- Outputs the table to a CSV file (for reading by Excel).
createCSVEventFile = true;   		-- Outputs events to a CSV file.
createClassCSVFile = true;  		-- Outputs class-by-class summary to a CSV file.
createPercentagesCSVFile = true;	-- Outputs percentage summary to a CSV file.
createEventTotalsCSVFile = true;	-- Outputs event-totals CSV file.

--createWinrarArchive = true;  		-- Uses WinRAR (assuming you have it installed) to zip all created reports.

-----------
-- FILES --
-----------
dofile("DMReporter_settings.lua");
dofile("DamageMeters_Globals.lua");
dofile(savedVariablesPath);
dofile("localization.lua");
dofile("DamageMeters_Report.lua");

------------------------------------------------------------------------
-- FUNCTIONS --
------------------------------------------------------------------------

-- Placeholders for built-in WOW functions.
function GetTime() return 0; end
function UnitName(unit) return "["..unit.."]"; end

function DMPrint(msg, color, bSecondChatWindow)
	io.write(msg.."\n");
end

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


function DamageMeters_SendReportMsg(msg)
	-- Send the message to the output file.
	outputFileHandle:write(msg.."\n");
end

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

-- This is a convenient function for output the main table data to a CSV file.
function DMReporter_OutputToCSV(outputFilename)
	-- Open the file.
	outputFileHandle = io.open(outputFilename, "w+");
	if (nil == outputFileHandle) then
		io.write("Error opening "..outputFilename);
		return;
	end
	io.write("(CSV) Reporting to "..outputFilename.."...\n");

	-- Generate header string.
	local msg, quant;
	msg = "Player,Class";
	for quant = 1, DMI_REPORT_MAX do
		msg = msg..","..DM_QUANTDEFS[quant].name..",Hits,Crits";
	end
	msg = msg..",,Net Dmg,Net Healing";
	DamageMeters_SendReportMsg(msg);

	-- Generate per-player strings.
	local index;
	for index = 1, table.getn(DamageMeters_tables[DMT_ACTIVE]) do
		local struct = DamageMeters_tables[DMT_ACTIVE][index];
		msg = struct.player..",";
		if (struct.class) then
			msg = msg..struct.class;
		end

		local quant;
		for quant = 1, DMI_REPORT_MAX do
			msg = msg..","..struct.dmiData[quant].q..","..struct.dmiData[quant].hitCount..","..struct.dmiData[quant].critCount;
		end
		
		local netDamage = struct.dmiData[DMI_DAMAGE].q - struct.dmiData[DMI_DAMAGED].q;
		local netHealing = struct.dmiData[DMI_HEALING].q - struct.dmiData[DMI_HEALED].q;
		msg = msg..",,"..netDamage..","..netHealing

		DamageMeters_SendReportMsg(msg);
	end

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

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

	-- Generate header string.
	local msg, quant;
	msg = "Player,Class,Quantity,Event,Total,Hits,Crits,Crit Pct,Avg,Pct of Player,Pct of Group,Dmg Type,Avg Res.";
	DamageMeters_SendReportMsg(msg);

	groupTotals = {};
	local ii;
	for ii = 1, table.getn(DamageMeters_tables[DMT_ACTIVE]) do
		local q;
		for q = 1, DMI_MAX do
			if (groupTotals[q] == nil) then
				groupTotals[q] = 0;
			end
			groupTotals[q] = groupTotals[q] + DamageMeters_tables[DMT_ACTIVE][ii].dmiData[q].q;
		end
	end

	-- Generate per-event strings.
	local struct, player, playerStruct, quantity, quantityStruct, spell, spellStruct;
	for index, struct in DamageMeters_tables[DMT_ACTIVE] do
		player = struct.player;
		for dmi = 1, DMI_MAX do
			quantityStruct = struct.dmiData[dmi].events;
			if (quantityStruct) then
				local playerClass = "";
				local fr = "";
				local playerIndex = DamageMeters_GetPlayerIndex(player);
				if (playerIndex and playerIndex > 0) then
					playerClass = DamageMeters_tables[DMT_ACTIVE][playerIndex].class;
				end
				if (nil == playerClass) then 
					playerClass = ""; 
				end

				local quantityTotal = 0;
				for spell, spellStruct in quantityStruct.spellTable do
					if (string.sub(spell, -1) ~= "*") then
						quantityTotal = quantityTotal + spellStruct.value;
					end
				end

				for spell, spellStruct in quantityStruct.spellTable do
					local average = DM_GetFraction(spellStruct.value, spellStruct.counts[1]);
					local pctCrit = 100 * DM_GetFraction(spellStruct.counts[2], spellStruct.counts[1]);
					local pctOfPlayer = 100 * DM_GetFraction(spellStruct.value, quantityTotal);
					local pctOfGroup = 100 * DM_GetFraction(spellStruct.value, groupTotals[dmi]);
					local avgRes = "";
					if (spellStruct.resistanceCount > 0) then
						avgRes = string.format("%.1f", DM_GetFraction(spellStruct.resistanceSum, spellStruct.resistanceCount));
					end

					msg = string.format("%s,%s,%s,%s,%d,%d,%.1f,%d,%.1f,%.1f,%.1f,%s,%s", 
						player, 
						playerClass,
						DMI_NAMES[dmi],
						spell,
						spellStruct.value,
						spellStruct.counts[1],
						spellStruct.counts[2],
						pctCrit,
						average,
						pctOfPlayer,
						pctOfGroup,
						(DM_DMGTYPE_DEFAULT == spellStruct.damageType) and "" or DM_DMGTYPENAMES[spellStruct.damageType],
						avgRes);
					DamageMeters_SendReportMsg(msg);
				end
			end
		end
	end

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

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

	local spellTable = {};
	local quantityTotals = {};
	for quantity = 1, DMI_MAX do
		spellTable[quantity] = {};
		quantityTotals[quantity] = 0;
	end

	-- Add up all the spells.
	local index, player, playerStruct, quantity, quantityStruct, spell, spellStruct;
	for index, playerStruct in DamageMeters_tables[DMT_ACTIVE] do
		for quantity = 1, DMI_MAX do
			eventStruct = playerStruct.dmiData[quantity].events;
			if (eventStruct) then
				for spell, spellStruct in eventStruct.spellTable do
					if (string.sub(spell, -1) ~= "*") then
						if (nil == spellTable[quantity][spell]) then
							spellTable[quantity][spell] = {};
							spellTable[quantity][spell].players = 0;
							spellTable[quantity][spell].value = 0;
							spellTable[quantity][spell].counts = {};
							spellTable[quantity][spell].counts[1] = 0;
							spellTable[quantity][spell].counts[2] = 0;
						end
						spellTable[quantity][spell].players		= spellTable[quantity][spell].players + 1;
						spellTable[quantity][spell].value		= spellTable[quantity][spell].value + spellStruct.value;
						spellTable[quantity][spell].counts[1]	= spellTable[quantity][spell].counts[1] + spellStruct.counts[1];
						spellTable[quantity][spell].counts[2]	= spellTable[quantity][spell].counts[2] + spellStruct.counts[2];

						quantityTotals[quantity] = quantityTotals[quantity] + spellStruct.value;
					end
				end
			end
		end
	end

	local msg = "Quantity,Spell,Players,Total,Hits,Crits,Average,Pct. Of Total";
	DamageMeters_SendReportMsg(msg);

	for quantity = 1, DMI_MAX do
		local quantityStruct = spellTable[quantity];
		for spell, spellStruct in quantityStruct do
			local average = DM_GetFraction(spellStruct.value, spellStruct.counts[1]);
			local percent = 100 * DM_GetFraction(spellStruct.value, quantityTotals[quantity]);

			local msg = string.format("%s,%s,%d,%d,%d,%d,%.1f,%.1f",
					DMI_NAMES[quantity],
					spell,
					spellStruct.players,
					spellStruct.value,
					spellStruct.counts[1],
					spellStruct.counts[2],
					average,
					percent);
			DamageMeters_SendReportMsg(msg);
		end
	end

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

⌨️ 快捷键说明

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