o
    z!h+                     @   sx   d dl Z g dZe ZdZdZdZdZeZeZ	G dd dZ
G d	d
 d
ZG dd dZG dd dZG dd dZdS )    N)FitChunk	FitHeaderFitCRCFitDefinitionMessageFitDataMessageFIT_FRAME_HEADERFIT_FRAME_CRCFIT_FRAME_DEFINITIONFIT_FRAME_DATAFIT_FRAME_DEFMESGFIT_FRAME_DATAMESG            c                   @   s   e Zd ZdZdd ZdS )r   indexoffsetbytesc                 C      || _ || _|| _d S Nr   )selfr   r   r    r   G/var/www/html/gps/gps/lib/python3.10/site-packages/fitdecode/records.py__init__      
zFitChunk.__init__N)__name__
__module____qualname__	__slots__r   r   r   r   r   r      s    r   c                   @      e Zd ZeZdZdd ZdS )r   header_size	proto_verprofile_ver	body_sizecrccrc_matchedchunkc                 C   s.   || _ || _|| _|| _|| _|| _|| _d S r   r!   )r   r"   r#   r$   r%   r&   r'   r(   r   r   r   r   )   s   
zFitHeader.__init__N)r   r   r   r   
frame_typer   r   r   r   r   r   r   "   s    r   c                   @   r    )r   r&   matchedr(   c                 C   r   r   r*   )r   r&   r+   r(   r   r   r   r   :   r   zFitCRC.__init__N)r   r   r   r   r)   r   r   r   r   r   r   r   5   s    r   c                   @   s4   e Zd ZeZdZdd Zedd Zedd Z	dS )	r   	is_developer_datalocal_mesg_numtime_offset	mesg_typeglobal_mesg_numendian
field_defsdev_field_defsr(   c
           
      C   s:   || _ || _|| _|| _|| _|| _|| _|| _|	| _d S r   r,   )
r   r-   r.   r/   r0   r1   r2   r3   r4   r(   r   r   r   r   R   s   
zFitDefinitionMessage.__init__c                 C   s   | j d ur	| j jS d| j S )Nunknown_)r0   namer1   r   r   r   r   r6   `   s   
zFitDefinitionMessage.namec                 C   s   | j s| jS t| j| j S r   )r4   r3   	itertoolschainr7   r   r   r   all_field_defsg   s   z#FitDefinitionMessage.all_field_defsN)
r   r   r   r   r)   r   r   propertyr6   r:   r   r   r   r   r   @   s    
r   c                   @   s   e Zd ZeZdZdd Zdd Zedd Z	edd	 Z
ed
d Zdd ZdddZdd ZdeddedddZdeddedddZddedddZdS )r   r-   r.   r/   def_mesgfieldsr(   c                 C   s(   || _ || _|| _|| _|| _|| _d S r   r<   )r   r-   r.   r/   r=   r>   r(   r   r   r   r   {   s   
zFitDataMessage.__init__c                 C   s
   t | jS )z2Iterate over the `FieldData` object in this mesage)iterr>   r7   r   r   r   __iter__   s   
zFitDataMessage.__iter__c                 C      | j jS )zMessage name)r=   r6   r7   r   r   r   r6         zFitDataMessage.namec                 C   rA   )z0The **global** definition number of this message)r=   r1   r7   r   r   r   r1      rB   zFitDataMessage.global_mesg_numc                 C   rA   )z6The `MessageType` object this message is associated to)r=   r0   r7   r   r   r   r0      rB   zFitDataMessage.mesg_typec                 C   s    | j D ]
}||r dS qdS )z
        Is the desired field present in this message?

        *field_name_or_num* is the name of the field (`str`), or its definition
        number (`int`).

        .. seealso:: `get_field`, `get_fields`, `get_value`, `get_values`
        TFr>   is_namedr   field_name_or_numfieldr   r   r   	has_field   s
   
	
zFitDataMessage.has_fieldr   c                 C   sP   d}| j D ]}||r|d7 }||kr|  S qtd| d| d| j d)ax  
        Get the desired `FieldData` object.

        *field_name_or_num* is the name of the field (`str`), or its definition
        number (`int`).

        *idx* is the zero-based index of the specified field **among other
        fields with the same name/number**. I.e. not the index of the field in
        the list of fields of this message. That is, ``idx=0`` is the first
        *field_name_or_num* field found in this message.

        *idx* is useful in case a message contains multiple fields with the same
        *field_name_or_num*.

        .. seealso:: `get_fields`, `get_value`, `get_values`, `has_field`
        r   field "" (idx #) not found in message "")r>   rD   KeyErrorr6   )r   rF   idxcurrent_idxrG   r   r   r   	get_field   s   

zFitDataMessage.get_fieldc                 c   s"    | j D ]
}||r|V  qdS )z
        Like `get_field` but **yield** every `FieldData` object matching
        *field_name_or_num* fields in this message - i.e. generator.

        .. seealso:: `get_field`, `get_value`, `get_values`, `has_field`
        NrC   rE   r   r   r   
get_fields   s   

zFitDataMessage.get_fieldsTNrO   fallback	raw_valuefit_typepy_typec                C   s   | j ||||||dS )NrS   )	get_value)r   rF   rO   rT   rU   rV   rW   r   r   r   get_raw_value   s   zFitDataMessage.get_raw_valueFc                C   s  |t u s|du st|tsJ d}|du r/z| j| }|j}d| d}W n" ty.   Y nw d}| jD ]}	|	|rG|d7 }||krG|	} nq4|du ra|t u r_td| d| d| j d	|S |r|jj|krt	d
| j d| d| d|jj d| d|s|j
n|j}
|t urt|
|st|ttfrddd |D }ntt|}t	d| j d| d| dt|
 d| d|
S )a  
        Get the value (or raw_value) of a field specified by its name or its
        definition number (*field_name_or_num*), with optional type checking.

        *idx* has the same meaning than for `get_field`.

        *fallback* can be specified to avoid `KeyError` being raised in case no
        field matched *field_name_or_num*.

        *fit_type* can be a `str` to indicate a given FIT type is expected (as
        defined in FIT profile; e.g. ``date_time``, ``manufacturer``, ...), in
        which case `TypeError` may be raised in case of a type mismatch.

        *py_type* can be a Python type or a `tuple` of types to expect (as
        passed to `isinstance`), in which case `TypeError` may be raised in case
        of a type mismatch.

        *raw_value* can be set to a true value so that the returned value is
        field's ``raw_value`` property instead of ``value``. This does not
        impact the way *fit_type* and *py_type* are interpreted.

        Special case: *field_name_or_num* can be `None`, in which case the field
        will be selected using *idx* only. In this case, *idx* is interpreted to
        be the zero-based index in the list of fields.

        .. seealso:: `get_values`, `get_field`, `get_fields`, `has_field`
        N[]rI   r   rJ   rK   rL   rM   zunexpected type for FIT field ".z; got z instead of )z or c                 S   s   g | ]}t t|qS r   )strtype).0tr   r   r   
<listcomp>/  s    z,FitDataMessage.get_value.<locals>.<listcomp>zunexpected type for FIT value ")_UNSET
isinstancer^   r>   name_or_numrN   rD   r6   r_   	TypeErrorvaluerU   tuplelistjoin)r   rF   rO   rT   rU   rV   rW   
field_datarP   rG   rg   py_type_strr   r   r   rX      s|   


zFitDataMessage.get_value)rU   rV   rW   c                c   s>    t | jD ]\}}||r| jd||||d}|V  qdS )a  
        Like `get_value` but **yield** every value of all the fields that match
        *field_name_or_num* - i.e. generator.

        It is not possible to specify a *fallback* value so `KeyError` will
        always be raised in case the specified field was not found.

        The other arguments have the same meaning than for `get_value`.

        .. seealso:: `get_value`, `get_field`, `get_fields`, `has_field`
        N)rO   rU   rV   rW   )	enumerater>   rD   rX   )r   rF   rU   rV   rW   rO   rk   rg   r   r   r   
get_values:  s   
zFitDataMessage.get_values)r   )r   r   r   r   r)   r   r   r@   r;   r6   r1   r0   rH   rQ   rR   rc   rY   rX   rn   r   r   r   r   r   n   s.    




[r   )r8   __all__objectrc   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   <module>   s   	.