2002-11-22 Christian Stimming <stimming@tuhh.de>

* src/import-export/Transaction-matcher.c: Fix the case when
	trans_online_id exists but is empty. Simplify heuristics for date
	matching. Increase exact amount matching value.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7521 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2002-11-22 00:06:17 +00:00
parent dd296d34f3
commit a92e78fad9
2 changed files with 42 additions and 36 deletions

View File

@ -1,3 +1,9 @@
2002-11-22 Christian Stimming <stimming@tuhh.de>
* src/import-export/Transaction-matcher.c: Fix the case when
trans_online_id exists but is empty. Simplify heuristics for date
matching. Increase exact amount matching value.
2002-11-21 Derek Atkins <derek@ihtfp.com> 2002-11-21 Derek Atkins <derek@ihtfp.com>
* business-core/test/*.c -- fix the tests for begin/commit edit * business-core/test/*.c -- fix the tests for begin/commit edit

View File

@ -788,15 +788,18 @@ static void split_find_match( struct _transmatcherdialog * matcher,
struct _matchinfo * match_info; struct _matchinfo * match_info;
double downloaded_split_amount; double downloaded_split_amount;
double match_split_amount; double match_split_amount;
time_t temp_time_t; time_t match_time, download_time;
struct tm downloaded_split_date; int datediff_day;
struct tm match_split_date;
DEBUG("Begin"); DEBUG("Begin");
/*Ignore the split if the transaction is open for edit, meaning it was just downloaded /*Ignore the split if the transaction is open for edit, meaning it
Ignore the split if the transaction has an online ID, unless overriden in prefs */ was just downloaded. Ignore the split if the transaction has an
if(xaccTransIsOpen(xaccSplitGetParent(split))==FALSE&& online ID , unless overriden in prefs (i.e. do not ignore the
(gnc_import_get_trans_online_id(xaccSplitGetParent(split))==NULL || SHOW_TRANSACTIONS_WITH_UNIQUE_ID==TRUE)) split if the online_id kvp is NULL or if it has zero length). */
if ((xaccTransIsOpen(xaccSplitGetParent(split)) == FALSE) &&
((gnc_import_get_trans_online_id(xaccSplitGetParent(split))==NULL) ||
(strlen(gnc_import_get_trans_online_id(xaccSplitGetParent(split))) == 0) ||
SHOW_TRANSACTIONS_WITH_UNIQUE_ID==TRUE))
{ {
match_info = g_new0(struct _matchinfo,1); match_info = g_new0(struct _matchinfo,1);
@ -807,10 +810,8 @@ static void split_find_match( struct _transmatcherdialog * matcher,
/*DEBUG(" downloaded_split_amount=%f", downloaded_split_amount);*/ /*DEBUG(" downloaded_split_amount=%f", downloaded_split_amount);*/
match_split_amount=gnc_numeric_to_double(xaccSplitGetAmount(split)); match_split_amount=gnc_numeric_to_double(xaccSplitGetAmount(split));
/*DEBUG(" match_split_amount=%f", match_split_amount);*/ /*DEBUG(" match_split_amount=%f", match_split_amount);*/
temp_time_t = xaccTransGetDate(xaccSplitGetParent(split)); match_time = xaccTransGetDate (xaccSplitGetParent (split));
match_split_date = *localtime(&temp_time_t); download_time = xaccTransGetDate (transaction_info->trans);
temp_time_t = xaccTransGetDate(transaction_info->trans);
downloaded_split_date = *localtime(&temp_time_t);
/* Matching heuristics */ /* Matching heuristics */
match_info->probability=0; match_info->probability=0;
@ -819,8 +820,8 @@ static void split_find_match( struct _transmatcherdialog * matcher,
if(gnc_numeric_equal(xaccSplitGetAmount(transaction_info->first_split), if(gnc_numeric_equal(xaccSplitGetAmount(transaction_info->first_split),
xaccSplitGetAmount(split))) xaccSplitGetAmount(split)))
{ {
match_info->probability=match_info->probability+2; match_info->probability=match_info->probability+3;
DEBUG("heuristics: probability + 2 (amount)"); DEBUG("heuristics: probability + 3 (amount)");
} }
else if(fabs(downloaded_split_amount-match_split_amount)<=MATCH_ATM_FEE_TRESHOLD) else if(fabs(downloaded_split_amount-match_split_amount)<=MATCH_ATM_FEE_TRESHOLD)
{ {
@ -838,29 +839,24 @@ static void split_find_match( struct _transmatcherdialog * matcher,
} }
/* Date heuristics */ /* Date heuristics */
if(downloaded_split_date.tm_year==match_split_date.tm_year) datediff_day = abs(match_time - download_time)/86400;
/* Sorry, there are not really functions around at all that
provide for less hacky calculation of days of date
differences. Whatever. On the other hand, the difference
calculation itself will work regardless of month/year
turnarounds. */
/*DEBUG("diff day %d", datediff_day);*/
if (datediff_day == 0)
{ {
if(downloaded_split_date.tm_yday==match_split_date.tm_yday) match_info->probability=match_info->probability+2;
{ DEBUG("heuristics: probability + 2 (date)");
match_info->probability=match_info->probability+2;
DEBUG("heuristics: probability + 2 (date)");
}
else if(downloaded_split_date.tm_yday>match_split_date.tm_yday&&
downloaded_split_date.tm_yday<=match_split_date.tm_yday+MATCH_DATE_TRESHOLD)
{
match_info->probability=match_info->probability+1;
DEBUG("heuristics: probability + 1 (date)");
}
/*Note: The above won't won't work as expected for transactions close to the end of the year.
So we have this special case to handle it:*/
else if(downloaded_split_date.tm_year==match_split_date.tm_year+1&&
match_split_date.tm_yday+MATCH_DATE_TRESHOLD>=365&&
downloaded_split_date.tm_yday<=match_split_date.tm_yday+MATCH_DATE_TRESHOLD-365)
{
match_info->probability=match_info->probability+1;
DEBUG("heuristics: probability + 1 (date special case)");
}
} }
else if (datediff_day <= MATCH_DATE_TRESHOLD)
{
match_info->probability=match_info->probability+1;
DEBUG("heuristics: probability + 1 (date)");
}
/* Memo heuristics */ /* Memo heuristics */
if((strcmp(xaccSplitGetMemo(transaction_info->first_split), if((strcmp(xaccSplitGetMemo(transaction_info->first_split),
@ -902,7 +898,8 @@ static void split_find_match( struct _transmatcherdialog * matcher,
DEBUG("heuristics: probability + 1 (description)"); DEBUG("heuristics: probability + 1 (description)");
} }
if(gnc_import_get_trans_online_id(xaccSplitGetParent(split))!=NULL) if ((gnc_import_get_trans_online_id(xaccSplitGetParent(split))!=NULL) &&
(strlen(gnc_import_get_trans_online_id(xaccSplitGetParent(split)))>0))
{ {
/*If the pref is to show match even with online ID's, reverse the confidence value to distinguish them */ /*If the pref is to show match even with online ID's, reverse the confidence value to distinguish them */
match_info->probability=0-match_info->probability; match_info->probability=0-match_info->probability;
@ -992,7 +989,10 @@ void gnc_import_add_trans(Transaction *trans)
/*For each split in the transaction, check if the parent account contains a transaction /*For each split in the transaction, check if the parent account contains a transaction
with the same online id.*/ with the same online id.*/
for(i=0;(source_split=xaccTransGetSplit(trans,i))!=NULL&&(trans_not_found==TRUE);i++) for (i=0;
((source_split = xaccTransGetSplit(trans, i)) != NULL) &&
(trans_not_found==TRUE);
i++)
{ {
DEBUG("%s%d%s","Checking split ",i," for duplicates"); DEBUG("%s%d%s","Checking split ",i," for duplicates");
dest_acct=xaccSplitGetAccount(source_split); dest_acct=xaccSplitGetAccount(source_split);