我有一个数据生成项目,我需要将生成的数据与另一个变量相匹配。
例如。曼联 - 利物浦队回归英超联赛 巴萨 - 真正的马德里回归西甲
我需要使用switch case方法generateLeague,它应该对类MatchEvent中的String匹配变量起作用。我所做的编码似乎没有捕获生成的MatchEvent匹配值,也没有返回字符串作为String leagueName = generateLeague没有收到String。它表示BetEvent中的generateLeague(String)无法应用。
这是具有数据生成的MatchEvent类(这确实有效)。
from bs4 import BeautifulSoup
soup = BeautifulSoup('<BR><CENTER><TABLE BORDER=1 CELLPADDING=0 NOSAVE><TR ALIGN=CENTER NOSAVE><TD COLSPAN="4" NOSAVE><CENTER><B>Summary Table</B></CENTER><TR><TD>Testname</TD><TD>Status</TD><TD>Link to HTML
</TD><TD>Utility</TD></TR><TR><TD>test1</TD><TD>FAIL</TD><TD><A HREF= abc.html>HTML_report</a></BR></TD><TD>run</TD></TR><TR><TD>31Jan2017_03h12m52s</TD><TD>FAIL</TD><TD><A HREF=def.html>HTML_report</a></BR></TD
><TD>run_2</TD></TR></TABLE></CENTER><BR>')
for link in soup.find_all('a'):
link['href'] = 'fix the absolute path here %s' % (link.get('href'),)
print soup.prettify()
这是使用Switch case语句的generateLeague方法。
/**
* Mock a transaction for testing purposes
*/
public MatchEvent generateEvent() {
try {
DataFactory df = new DataFactory();
// BetEvent
int betID = df.getNumberBetween(220000000, Integer.MAX_VALUE);
float odds = df.getNumberBetween((int) 1.05, 30);
// Selections
String selectionID = UUID.randomUUID().toString();
// Market
// Event
String eventID = UUID.randomUUID().toString();
String match = df.getItem(StaticTestData.match, 80, "Liverpool vs Manchester Utd"); // should match league and categoryID
//SubCategory
// category
final int categoryID = 1; // LeagueID by number eg. 1 is for LaLiga, should match MatchLeague and Match
final String categoryName = "Football";
// Subcategory
String subCategoryID = UUID.randomUUID().toString();
String leagueName = generateLeague(); // should match Match and category ID
final String parentSubCategory = null;
// market
final String name = null;
float matchOdds = df.getNumberBetween((int) 1.05, 30); // since focusing on prematch should keep maxNo 20?
//betEvent
float stake = df.getNumberBetween(0, 1200);
boolean mobile = Math.random() < 0.5;
final String providerName = "EPBetsSportsbook";
float totalOdds = matchOdds;
float totalStake = stake;
String nation = df.getItem(StaticTestData.countryCodes); // should make it as realistic as possible
final String currency = "EUR";
Date date = new Date();
java.text.DateFormat formatter = new java.text.SimpleDateFormat("MM-dd-yyyy");
String calendarDate = formatter.format(date);
return new MatchEvent(betID, odds, selectionID, eventID, match, categoryID, categoryName, subCategoryID,
leagueName, parentSubCategory, name, matchOdds, stake, mobile, providerName,
totalOdds, totalStake, nation, date, currency, calendarDate);
} catch (Exception e) {
// For demo purposes, we are not going to log errors/send to a kafka stream
throw e;
}
}
我将非常感谢并提前感谢您的任何指导。
答案 0 :(得分:1)
如果String匹配中没有空格,那么club将为null。然后它当然不会正常切换。你需要在if语句中添加else语句。您也可能希望确保俱乐部是小写的。像这样:
if (match.toLowerCase().contains(" ")) {
club = match.toLowerCase().substring(0, match.indexOf(" "));
} else {
club = match.toLowerCase();
}
另一件事:在generateEvent中:你有generateLeague()。这不会编译。做generateLeague(匹配);
答案 1 :(得分:1)
String leagueName = generateLeague没有收到String。它说 无法应用BetEvent中的generateLeague(String)。
它之所以如此,是因为您的generateLeague
方法需要String
参数
public static String generateLeague(String match)
{
//content
}
但是从generateEvent
方法
String leagueName = generateLeague();
您不在String
方法中传递generateLeague
作为参数。