Quantcast

Rolled addon:ScanSkillLevelData() into addon:ScanTrainerData() - There was much duplicated code and they were both ran simultaneously when scanning trainers, overwriting the output buffer of one with the other. Now trainer scans report which recipe levels were corrected, and which could not be because they could not be confirmed with an item ID.

James D. Callahan III [03-13-11 - 12:24]
Rolled addon:ScanSkillLevelData() into addon:ScanTrainerData() - There was much duplicated code and they were both ran simultaneously when scanning trainers, overwriting the output buffer of one with the other. Now trainer scans report which recipe levels were corrected, and which could not be because they could not be confirmed with an item ID.
Filename
Config.lua
Locales/devel-enUS.lua
Scanner.lua
core.lua
diff --git a/Config.lua b/Config.lua
index d29a679..c7372e0 100644
--- a/Config.lua
+++ b/Config.lua
@@ -26,7 +26,7 @@ local AceConfigReg 	= LibStub("AceConfigRegistry-3.0")
 local AceConfigDialog 	= LibStub("AceConfigDialog-3.0")

 -- Set up the private intra-file namespace.
-local private	= select(2, ...)
+local FOLDER_NAME, private	= ...

 local modularOptions = {}

@@ -358,14 +358,6 @@ local function GetDatamineOptions()
 					desc	= L["GENERATE_LINKS_DESC"],
 					func	= function() addon:GenerateLinks() end,
 				},
-				scantrainerskills = {
-					width	= "double",
-					order	= 20,
-					type	= "execute",
-					name	= L["Compare Trainer Skills"],
-					desc	= L["COMPARE_TRAINER_SKILL_DESC"],
-					func	= function() addon:ScanSkillLevelData() end,
-				},
 				scantraineracquire = {
 					width	= "double",
 					order	= 30,
diff --git a/Locales/devel-enUS.lua b/Locales/devel-enUS.lua
index 8bf7432..8c9b98a 100644
--- a/Locales/devel-enUS.lua
+++ b/Locales/devel-enUS.lua
@@ -224,7 +224,6 @@ L["COMMON_ISSUES_DESC"] = [=[Please refer to these common issues before submitti
 2) Inscription is missing so many glyphs! Why aren't they listed?  Turn off your 'classes' filter.  By default (and due to popular request) ARL will only show recipes which your class can use and most glyphs are not usable by your class.
 3) I don't want to see opposite faction recipes! Turn on the factions filter.  This will set it up to only display your factions obtainable recipes.  If something still shows up and it shouldn't, please submit a bug report.]=]
 L["COMPARE_TRAINER_ACQUIRE_DESC"] = "Compare selected trainer acquire methods with those in the ARL database."
-L["COMPARE_TRAINER_SKILL_DESC"] = "Compare skill levels of selected trainer with those in ARL database."
 L["CONTRACTALL_DESC"] = "Minimize all recipes listed below."
 L["CRAFTED_ENGINEERS"] = "Recipe is created by Engineers."
 L["CROSSBOW_DESC"] = "Recipes that make crossbows should be included in the scan."
@@ -264,7 +263,6 @@ L["Coilfang Sorceress"] = "Coilfang Sorceress"
 L["Coilskar Siren"] = "Coilskar Siren"
 L["Common Issues"] = "Common Issues"
 L["Compare Trainer Acquire"] = "Compare Trainer Acquire"
-L["Compare Trainer Skills"] = "Compare Trainer Skills"
 L["Constance Brisboise"] = "Constance Brisboise"
 L["Cook Ghilm"] = "Cook Ghilm"
 L["Cookie One-Eye"] = "Cookie One-Eye"
@@ -296,10 +294,6 @@ L["DAILY_COOKING_FISH"] = "Choose Barrel of Fish when completing any of these qu
 L["DAILY_COOKING_MEAT"] = "Choose Crate of Meat when completing any of these quests."
 L["DAILY_FISHING_SHATT"] = "Randomly obtained by completing any of the BC fishing daily quests."
 L["DATAMINER_NODB_ERROR"] = "Recipe database not loaded.  Please scan the tradeskill first then try the datamining."
-L["DATAMINER_SKILLELVEL"] = [=[Recipe level different!
-    Name: %s
-	ARL Level: %s
-	Trainer Level: %s]=]
 L["DATAMINER_SKILLLEVEL_ERROR"] = "This can only be used for a trade skill trainer.  Please open up the trainer and try again."
 L["DATAMINER_TRAINER_INFO"] = [=[Trainer Name: %s
 Trainer ID: %s]=]
diff --git a/Scanner.lua b/Scanner.lua
index e8f7804..63e326c 100644
--- a/Scanner.lua
+++ b/Scanner.lua
@@ -567,84 +567,11 @@ end
 local ARLDatamineTT = _G.CreateFrame("GameTooltip", "ARLDatamineTT", _G.UIParent, "GameTooltipTemplate")

 do
-	-- Tables used in all the Scan functions within this do block. -Torhal
-	local scanned_recipes, output = {}, {}
-
-	--- Function to compare the skill levels of a trainers recipes with those in the ARL database.
-	-- @name AckisRecipeList:ScanSkillLevelData
-	-- @param autoscan True when autoscan is enabled in preferences, it will surpress output letting you know when a scan has occured.
-	-- @return Does a comparison of the information in your internal ARL database, and those items which are available on the trainer.  Compares the skill levels between the two.
-	function addon:ScanSkillLevelData(autoscan)
-		if not _G.IsTradeskillTrainer() then
-			if not autoscan then
-				self:Print(L["DATAMINER_SKILLLEVEL_ERROR"])
-			end
-			return
-		end
-		local recipe_list = LoadRecipe()	-- Get internal database
-
-		if not recipe_list then
-			self:Print(L["DATAMINER_NODB_ERROR"])
-			return
-		end
-		-- Get the initial trainer filters
-		local avail = _G.GetTrainerServiceTypeFilter("available")
-		local unavail = _G.GetTrainerServiceTypeFilter("unavailable")
-		local used = _G.GetTrainerServiceTypeFilter("used")
-
-		-- Clear the trainer filters
-		_G.SetTrainerServiceTypeFilter("available", 1)
-		_G.SetTrainerServiceTypeFilter("unavailable", 1)
-		_G.SetTrainerServiceTypeFilter("used", 1)
-
-		table.wipe(scanned_recipes)
-
-		-- Get the skill levels from the trainer
-		for i = 1, _G.GetNumTrainerServices(), 1 do
-			local name = _G.GetTrainerServiceInfo(i)
-			local _, skilllevel = _G.GetTrainerServiceSkillReq(i)
-
-			if not skilllevel then
-				skilllevel = 0
-			end
-			scanned_recipes[name] = skilllevel
-		end
-		local found = false
-
-		table.wipe(output)
-
-		for i in pairs(recipe_list) do
-			local i_name = recipe_list[i].name
-
-			if scanned_recipes[i_name] and scanned_recipes[i_name] ~= recipe_list[i].skill_level then
-				found = true
-				table.insert(output, L["DATAMINER_SKILLELVEL"]:format(i_name, recipe_list[i].skill_level, scanned_recipes[i_name]))
-				recipe_list[i].skill_level = scanned_recipes[i_name]
-
-				local skill_level = recipe_list[i].skill_level
-				local optimal_level = recipe_list[i].optimal_level
-
-				if optimal_level > skill_level or optimal_level < skill_level then
-					recipe_list[i].optimal_level = skill_level
-					recipe_list[i].medium_level = skill_level + 10
-					recipe_list[i].easy_level = skill_level + 15
-					recipe_list[i].trivial_level = skill_level + 20
-				end
-			end
-		end
-		table.insert(output, "Trainer Skill Level Scan Complete.")
-
-		if found then
-			self:DisplayTextDump(nil, nil, table.concat(output, "\n"))
-		end
-		-- Reset the filters to what they were before
-		_G.SetTrainerServiceTypeFilter("available", avail or 0)
-		_G.SetTrainerServiceTypeFilter("unavailable", unavail or 0)
-		_G.SetTrainerServiceTypeFilter("used", used or 0)
-	end
-
-	local missing_spell_ids, extra_spell_ids, corrected_spell_ids = {}, {}, {}
-	local scanned_items, itemless_spells = {}, {}
+	-- Tables used in addon:ScanTrainerData
+	local scanned_recipes, scanned_items, output = {}, {}, {}
+	local missing_spell_ids, extra_spell_ids, fixed_item_spell_ids = {}, {}, {}
+	local mismatched_levels, mismatched_levels_unconfirmed = {}, {}
+	local itemless_spells = {}

 	--- Function to compare which recipes are available from a trainer and compare with the internal ARL database.
 	-- @name AckisRecipeList:ScanTrainerData
@@ -690,20 +617,26 @@ do

 		local trainer_profession = _G.GetTrainerServiceSkillLine(1)

-		-- Get all the names of recipes from the trainer
 		for index = 1, _G.GetNumTrainerServices(), 1 do
 			local item_name = _G.GetTrainerServiceInfo(index)
 			local item_id = ItemLinkToID(_G.GetTrainerServiceItemLink(index))
+			local _, skill_level = _G.GetTrainerServiceSkillReq(index)
+
+			if not skill_level then
+				skill_level = 0
+			end

 			if item_id then
-				scanned_items[item_id] = true
+				scanned_items[item_id] = skill_level
 			else
-				scanned_recipes[item_name] = true
+				scanned_recipes[item_name] = skill_level
 			end
 		end
 		table.wipe(missing_spell_ids)
 		table.wipe(extra_spell_ids)
-		table.wipe(corrected_spell_ids)
+		table.wipe(fixed_item_spell_ids)
+		table.wipe(mismatched_levels)
+		table.wipe(mismatched_levels_unconfirmed)
 		table.wipe(output)

 		-- Dump out trainer info
@@ -713,8 +646,6 @@ do
 		table.insert(output, "ARL Version: @project-version@")
 		table.insert(output, L["DATAMINER_TRAINER_INFO"]:format(trainer_name, trainer_id))

-		local current_profession
-
 		for spell_id, recipe in pairs(recipe_list) do
 			if trainer_profession == recipe.profession then
 				local train_data = recipe.acquire_data[A.TRAINER]
@@ -729,11 +660,13 @@ do
 					end
 				end
 				local matching_item = scanned_items[recipe:CraftedItemID()]
-				local matching_recipe = scanned_recipes[recipe.name] and not recipe:CraftedItemID()
+				local matching_recipe = scanned_recipes[recipe.name]

-				if matching_item or matching_recipe then
-					current_profession = recipe.profession
+				if recipe:CraftedItemID() then
+					matching_recipe = nil
+				end

+				if matching_item or matching_recipe then
 					if not matching_trainer then
 						recipe:AddTrainer(trainer_id)
 						table.insert(missing_spell_ids, spell_id)
@@ -748,6 +681,13 @@ do
 							end
 						end
 					end
+					local recipe_skill = recipe:SkillLevels()
+
+					if matching_item and matching_item ~= recipe_skill then
+						table.insert(mismatched_levels, spell_id)
+					elseif matching_recipe and matching_recipe ~= recipe_skill then
+						table.insert(mismatched_levels_unconfirmed, spell_id)
+					end
 				elseif matching_trainer then
 					table.wipe(itemless_spells)

@@ -761,7 +701,7 @@ do
 					end

 					if itemless_spells[spell_id] then
-						table.insert(corrected_spell_ids, spell_id)
+						table.insert(fixed_item_spell_ids, spell_id)
 					else
 						table.insert(extra_spell_ids, spell_id)
 					end
@@ -770,7 +710,9 @@ do
 		end
 		local found_missing = #missing_spell_ids > 0
 		local found_extra = #extra_spell_ids > 0
-		local found_corrected = #corrected_spell_ids > 0
+		local found_fixed_item = #fixed_item_spell_ids > 0
+		local found_wrong_level = #mismatched_levels > 0
+		local found_unconfirmed_level = #mismatched_levels_unconfirmed > 0

 		if found_missing then
 			table.insert(output, "\nTrainer is missing from the following entries:")
@@ -792,18 +734,44 @@ do
 			end
 		end

-		if found_corrected then
+		if found_fixed_item then
 			table.insert(output, "\nRecipes which had no crafted item ID, but will once a dump is performed:")
-			table.sort(corrected_spell_ids)
+			table.sort(fixed_item_spell_ids)

-			for index in ipairs(corrected_spell_ids) do
-				local spell_id = corrected_spell_ids[index]
+			for index in ipairs(fixed_item_spell_ids) do
+				local spell_id = fixed_item_spell_ids[index]
 				table.insert(output, ("%d (%s)"):format(spell_id, recipe_list[spell_id].name))
 			end
 		end

-		if found_missing or found_extra or found_corrected then
-			if found_extra and current_profession == private.professions.Engineering then
+		if found_wrong_level then
+			table.insert(output, "\nRecipes which had an incorrect skill level, but will not once a dump is performed:")
+			table.sort(mismatched_levels)
+
+			for index in ipairs(mismatched_levels) do
+				local spell_id = mismatched_levels[index]
+				local recipe = recipe_list[spell_id]
+				local recipe_skill = recipe:SkillLevels()
+				local corrected_skill = scanned_items[recipe:CraftedItemID()]
+				table.insert(output, ("%d (%s): Corrected skill level from %d to %d."):format(spell_id, recipe.name, recipe_skill, corrected_skill))
+				recipe:SetSkillLevels(corrected_skill)
+			end
+		end
+
+		if found_unconfirmed_level then
+			table.insert(output, "\nRecipes with possible incorrect skill levels - unable to confirm:")
+			table.sort(mismatched_levels_unconfirmed)
+
+			for index in ipairs(mismatched_levels_unconfirmed) do
+				local spell_id = mismatched_levels_unconfirmed[index]
+				local recipe = recipe_list[spell_id]
+				local recipe_skill = recipe:SkillLevels()
+				table.insert(output, ("%d (%s): Skill set to %d; trainer reports %d."):format(spell_id, recipe.name, recipe_skill, scanned_recipes[recipe.name]))
+			end
+		end
+
+		if found_missing or found_extra or found_fixed_item or found_wrong_level or found_unconfirmed_level then
+			if found_extra and trainer_profession == private.professions.Engineering then
 				table.insert(output, "\nSome goggles may be listed as extra. These goggles ONLY show up for the classes who can make them, so they may be false positives.")
 			end

diff --git a/core.lua b/core.lua
index 20a417a..284cdfc 100644
--- a/core.lua
+++ b/core.lua
@@ -746,13 +746,12 @@ end

 ---Event used for datamining when a trainer is shown.
 function addon:TRAINER_SHOW()
-	self:ScanSkillLevelData(true)
 	self:ScanTrainerData(true)
 end

 ---Event used for datamining when a vendor is shown.
 function addon:MERCHANT_SHOW()
-	addon:ScanVendor()
+	self:ScanVendor()
 end

 do
@@ -969,8 +968,6 @@ do
 					self:Scan(false, false)
 				end
 			end
-		elseif arg1 == "scandata" then
-			self:ScanSkillLevelData()
 		elseif arg1 == "scanprof" then
 			self:ScanProfession("all")
 		elseif arg1 == "tradelinks" then