예제 #1
0
    def _func_(self, data_list, args=None):

        # This function is meant to get the score from a data_list of four, 0-3 or NoDataError
        # In the data_list of four, it's possible to have 2 or 3 or 4 data. Under this
        # scenario, choose the highest score.
        # However, it's also possible to have 11 or 1 as the input. For these two, we all think it as
        # 1
        highest_bdi_score = -1 #-1 as the missing value
        bdi_score = -1
        for data in data_list:

            if isinstance(data, ssManager.NoDataError):
                pass
            else:
                data = str(data)
                bdi_score = data[0]
                try:
                    if int(bdi_score) >= highest_bdi_score:
                        highest_bdi_score = int(bdi_score)
                except KeyError as e:
                    raise Exception("The data contains Non-number")

        if bdi_score == -1:
            return ssManager.NoDataError("No data")

        return bdi_score
예제 #2
0
def sum_mean(data_list, args=[""]):
    #   import ipdb; ipdb.set_trace()

    # Set the default value for the args if the passed in args is ""
    if args == [""] or args == None or type(args) != list:
        args = [0.7, 'int']

    threshold = args[0]
    strtypearg = args[1]
    strtypes = {'float': float, 'int': int}
    strtype = strtypes[strtypearg]

    numMiss = 0
    data_sum = 0
    for num in data_list:
        if isinstance(num, ssManager.NoDataError):
            numMiss += 1
        else:
            #import ipdb; ipdb.set_trace()
            try:
                data_sum += strtype(num)
            except ValueError:
                numMiss += 1

    valid_num = len(data_list) - numMiss

    if numMiss / len(data_list) <= 1 - threshold:
        return data_sum, valid_num
    else:
        return ssManager.NoDataError()
예제 #3
0
    def _func_(self, data_list, args=None):
        if args == [""] or args == None or type(args) != list:
            args = [0.8, 'int']

        threshold = args[0]
        strtypearg = args[1]
        strtypes = {'float': float, 'int': int}
        strtype = strtypes[strtypearg]

        numMiss = 0
        data_sum = 0
        for num in data_list:
            if isinstance(num, ssManager.NoDataError):
                numMiss += 1
            else:
                # import ipdb; ipdb.set_trace()
                try:
                    data_sum += strtype(num)
                except ValueError:
                    numMiss += 1

        valid_num = len(data_list) - numMiss

        if numMiss / len(data_list) < 1 - threshold:
            return data_sum
        else:
            return ssManager.NoDataError()
예제 #4
0
    def _func_(self, data_list, args=None):

        # return the first element that has data.
        for data in data_list:
            if not isinstance(data, ssManager.NoDataError):
                return data

        return ssManager.NoDataError("No data for this field")
예제 #5
0
    def _func_(self, data_list, args=None):
        # the mapper will look like this. 1,2,{0} This denotes that the data corresponding with the first data will be
        # used in the female, and the data corresponding with the second will be used when the data corresponding to the
        # third column indicates male

        # This function should have 3 argumennts
        if len(data_list) != 3:
            # user_error_log.log_mapping_error("Gender Response should contain 3 mapping files")
            return ssManager.NoDataError(
                "Gender Response should contain 3 mapping files")

        # The male is "M", and "F" stands for female
        if data_list[2].strip() == "F":
            return data_list[0]
        elif data_list[2].strip() == "M":
            return data_list[1]
        else:
            return ssManager.NoDataError()
예제 #6
0
    def _func_(self, data_list, args=None):
        if len(data_list) != 1 and len(data_list) != 2:
            raise Exception("data_list should be length of 1 or 2")

        if len(data_list) == 1:
            # decide parent gender
            # then decide whether i should mother dob or father dob
            #
            dob_date = self._get_birth_date_(familyid=data_list[0], twin=3)

            if dob_date is None:
                return ssManager.NoDataError()

            assessment = self._get_assessment_date_(familyid=data_list[0])
            return self._calculate_age_(dob_date, assessment)

        else:
            dob_date = self._get_birth_date_(familyid=data_list[0],
                                             twin=data_list[1])
            if dob_date is None:
                return ssManager.NoDataError()
            assessment_date = self._get_assessment_date_(familyid=data_list[0])
            return self._calculate_age_(dob_date, assessment_date)
예제 #7
0
class FindGenderByWTPInt(Function):

    argument_number = 2

    # this mapping defines how to translate our database coding to NDAR requirement
    gender_mapping = {
        1: "F",
        2: "M",
        9998: ssManager.NoDataError("Empty gender")
    }

    def _func_(self, data_list, args=None):
        if len(data_list) != 1 and len(data_list) != 2:
            raise Exception("data_list should be length of 1 or 2")

        if len(data_list) == 1:
            # Use data_r1_tr to decide the gender for caregiver
            gender = self._get_gender_(familyid=data_list[0], twin=3)
            return self.gender_mapping[int(gender)]
        else:
            gender = self._get_gender_(familyid=data_list[0],
                                       twin=data_list[1])
            return self.gender_mapping[int(gender)]

    def _get_gender_(self, familyid, twin):
        con = get_open_connection()
        cur = con.cursor()
        sql = "SELECT gender FROM {0} WHERE familyid = '{1}' AND twin = {2}".format(
            rdoc_info, familyid, twin)
        cur.execute(sql)

        rows = cur.fetchmany()
        if len(rows) > 1:
            raise Exception(
                "Duplicate gender for caregiver. familyid: {0}".format(
                    familyid))
        if len(rows) == 0:
            raise Exception("No gender for familyid: %s, twin: %s" %
                            (familyid, twin))
        con.close()
        return rows[0][0]

    def get_documentation(self):
        return "Find gender given the familyid and twin or just familyid. Twin should always follow familyid"

    def get_name(self):
        return "findGenderByWTPInt"
예제 #8
0
    def get_ursi_from_wtpdata(self, familyid, twin):
        con = get_open_connection()
        cur = con.cursor()
        sql = "SELECT ursi FROM {table} WHERE familyid = '{familyid}' and twin = {twin}"\
            .format(table = guid_table, familyid = familyid, twin = twin)
        cur.execute(sql)
        rows = cur.fetchmany()
        if len(rows) > 1:
            raise Exception(
                "Duplicate ursi for twin: familyid: {0}".format(familyid))
        if len(rows) == 0:
            raise Exception("No ursi for familyid: %s " % familyid)
        con.close()
        ursi = rows[0][0]

        if ursi == "9998":
            return ssManager.NoDataError("Empty ursi")
        return ursi
예제 #9
0
    def _func_(self, data_list, args=None):
        if len(data_list) == 0:
            return ssManager.NoDataError()

        return ";".join([str(x) for x in data_list])
예제 #10
0
    def _func_(self, data_list, args=None):

        return ssManager.NoDataError("NO DATA")