---
# System prepended metadata

title: offset service

---

# offset service
## flowchart
![](https://i.imgur.com/BtTfE6j.png)

## 使用方式
``` python
#import pacakges
import requests
import random
import os 
import datetime
#input parameters 
job_type         = 'PCB' # or 'ST'
feature_name     = 'tf_fiducail' 
step_size        = (460, 406)

job_name         = 'depp-test'
update_pos       = [3.1, 5.1]
remove_pos       = [3.1, 5.1] #or None
database         = 'DEV' #or 'USER'
#取得錯位解 LIST #有feature_name 與 step_size的情況
band_info_list = get_band_pos_list(job_type,
                                   feature_name,
                                   step_size, 
                                   database='DEV')
#[[job_name, band_pos1, remove_pos1, date],
# [job_name, band_pos2, remove_pos2, date],
# [job_name, band_pos3, remove_pos3, date],...]

#取得錯位解 LIST #只有database的情況
#return 整份字典
main_band_pos_dict = get_band_pos_list(database='DEV')


#update band_pos
#若沒有執行filter band_pos，則不用填remove_pos
#反之，要填寫remove_pos，供程式排除重複的band_pos
update_band_pos(job_type,
                feature_name,
                job_name,
                step_size,pos,
                remove_pos=None,
                database = 'DEV')

```

## function

```python=
def update_band_pos(job_type,
                    feature_name,
                    job_name,
                    step_size,
                    update_pos,
                    remove_pos = None,
                    database = 'DEV'):
    '''
    input:
        job_type          : str -> 'PCB' or 'ST'
        feature_name      : str 
        step_size         : (int, int) -> accept only mm

        job_name          : str
        update_pos        : [float, float]
        remove_pos        : [float, float]
        database          : str -> default 
        #feature_info_list : [job_name, update_pos, remove_pos, date]:'DEV', optional : 'USER'
            
    '''        
    date = str(datetime.datetime.now().strftime("%Y-%m-%d"))
    feature_info_list = [job_name, update_pos, remove_pos, date]


    data = {'database'     : database,
            'job_type'     : job_type,
            'feature_name' : feature_name,
            'step_size'    : str(step_size),
            'feature_info_list' : str(feature_info_list)}
    #update
    
    r = requests.post("http://10.12.20.149:3113/cam/call_update_band_pos",
                           data = {"data": str(data)} )
    main_feature_pos_dict = eval(r.text)
    return main_feature_pos_dict 



def get_band_pos_list(job_type,
                      feature_name = '',
                      step_size = '',
                      database = 'DEV'):
    '''
    input:
        job_type          : str -> 'PCB' or 'ST'
        feature_name      : str 
        step_size         : (int, int) -> accept only mm
        database          : str -> default :'DEV', optional : 'USER'
    output:
        band_info_list    : [band_info, band_info...]
        band_info         : [job_name, band_pos, remove_pos, date -> str]

    '''      
    data = {'database'     : database,
            'job_type'     : job_type,
            'feature_name' : feature_name,
            'step_size'    : str(step_size)}
    #get band position
    r = requests.post("http://10.12.20.149:3113/cam/call_get_band_pos_list",
                           data = {"data": str(data) } )
    band_info_list = eval(r.text)
    return band_info_list


```
