Limiting the number of interviews per day in CSPro

What would you like to see in CSPro?
Post Reply
Rolyno
Posts: 13
Joined: February 19th, 2025, 3:44 am
Location: Cotonou

Limiting the number of interviews per day in CSPro

Post by Rolyno »

Hello,

To ensure the quality of the data collected in the field, we would like to limit the number of interviews that an enumerator can conduct per day.

To implement this, I wrote the following code:

Code: Select all

// Set the daily interview limit
numeric LIMITE_JOURNALIERE = 2;
numeric DATE_DERNIERE_ENQUETE;
numeric ENTREVUES_AUJOURDUI;

// Reset the counter if the date has changed
if (sysdate() <> DATE_DERNIERE_ENQUETE) then
    ENTREVUES_AUJOURDUI = 0;  // Reset counter
    DATE_DERNIERE_ENQUETE = sysdate();  // Update date
endif;

// Check if the daily limit is reached
if (ENTREVUES_AUJOURDUI >= LIMITE_JOURNALIERE) then
    errmsg("You have reached the daily interview quota (%d/%d).", ENTREVUES_AUJOURDUI, LIMITE_JOURNALIERE);
    stop;  // Block the interview
endif;


Is there a more efficient or recommended way to implement this logic in CSPro?
Thank you in advance for your advice and suggestions.
Gregory Martin
Posts: 1946
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Limiting the number of interviews per day in CSPro

Post by Gregory Martin »

You don't show where you increment ENTREVUES_AUJOURDUI, but assuming that you do this at the end of the case, I would just like to point out a couple things:

- Your code will not allow for someone to add a case and then modify it, as that modification will (presumably) be counted as a new case. Maybe this isn't an issue given your workflow.

- Your ENTREVUES_AUJOURDUI counter will always start as 0 when the interviewer opens CSEntry, so they can bypass this check by closing CSEntry and then opening it again.

To avoid the second problem, you will want to use a variable whose lifetime outlasts a single instance of CSEntry. You can do this by making the variables persistent (if using CSPro 8.0), or by using loadsetting/savesetting:

https://www.csprousers.org/help/CSPro/p ... ifier.html
https://www.csprousers.org/help/CSPro/l ... ction.html

If using CSPro 8.0, I'd probably implement this using a HashMap object. See the code here, and attached for an example that you can run:
// this code belongs in the PROC where the final case ID is entered

// cases_by_day will map case keys to the date they were initially entereed
persistent HashMap cases_by_day(string) default(notappl);

numeric today = sysdate("YYYYMMDD");
string this_case_key = currentkey(LIMIT_CASES_PER_DAY_DICT);

// check if this case has already been entered (if so, we are in modify mode)
numeric date_case_entered = cases_by_day(this_case_key);

// if this is a new case, verify that there have not been too many new cases entered today 
if date_case_entered = notappl then

    List string
all_cases_entered;
    cases_by_day.getKeys(all_cases_entered);
   
    numeric cases_entered_today = 0;
   
    do numeric ctr = 1 while ctr <= all_cases_entered.length()

        if cases_by_day(all_cases_entered(ctr)) = today then

            inc
(cases_entered_today);
           
            if cases_entered_today = 2 then
                errmsg
("You cannot enter more than 2 cases per day.");
                reenter;
            endif;
           
        endif;

    enddo;

    // add this new case to the list of cases entered today
   
cases_by_day(this_case_key) = today;

endif;
Limit-Cases-Per-Day.zip
You do not have the required permissions to view the files attached to this post.
Rolyno
Posts: 13
Joined: February 19th, 2025, 3:44 am
Location: Cotonou

Re: Limiting the number of interviews per day in CSPro

Post by Rolyno »

Thank you Grégory Martin for your helpful responses!
Rolyno
Posts: 13
Joined: February 19th, 2025, 3:44 am
Location: Cotonou

Re: Limiting the number of interviews per day in CSPro

Post by Rolyno »

I use the code to limit the number of recordings per day, but it doesn't work on certain phones. Some interviewers are able to exceed the set limit on their devices, and I don't know why.
Gregory Martin
Posts: 1946
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Limiting the number of interviews per day in CSPro

Post by Gregory Martin »

Do you have any clues about why it might work on some devices but not others? Are certain devices of one brand/model and others are of a different type? Have all the devices received your updated application?
Post Reply