code: def data_process_with_time(
      fname, pname, K=10, sep=" ", item_set=None, add_time=False
  ):
      User = defaultdict(list)
      Users = set()
      Items = set()
      user_dict, item_dict = {}, {}
  
      item_counter = defaultdict(lambda: 0)
      user_counter = defaultdict(lambda: 0)
      with open(fname, "r") as fr:
          for line in fr:
              u, i, t = line.rstrip().split(sep)
              User[u].append((i, t))
              Items.add(i)
              Users.add(u)
              item_counter[i] += 1
              user_counter[u] += 1
  
      # remove items with less than K interactions
      print(f"Read {len(User)} users and {len(Items)} items")
      remove_items = set()
      count_remove, count_missing = 0, 0
      for item in Items:
          if item_counter[item] < K:
              count_remove += 1
              remove_items.add(item)
          elif item_set and item not in item_set:
              count_missing += 1
              remove_items.add(item)
  
      if count_remove > 0:
          print(f"{count_remove} items have less than {K} interactions")
  
      if count_missing > 0:
          print(f"{count_missing} items are not in the meta data")
  
      Items = Items - remove_items
  
      # remove users with less than K interactions
      remove_users = set()
      count_remove = 0
      # Users = set(User.keys())
      for user in Users:
          if user_counter[user] < K:
              remove_users.add(user)
              count_remove += 1
      if count_remove > 0:
          print(f"{count_remove} users have less than {K} interactions")
          Users = Users - remove_users
  
      print(f"Total {len(Users)} users and {len(Items)} items")
      item_count = 1
      for item in Items:
          item_dict[item] = item_count
          item_count += 1
  
      count_del = 0
      user_count = 1
      with open(pname, "w") as fw:
          for user in Users:
              items = User[user]
              items = [tup for tup in items if tup[0] in Items]
              if len(items) < K:
                  count_del += 1
              else:
                  user_dict[user] = user_count
                  # sort by time
                  items = sorted(items, key=lambda x: x[1])
  
                  # replace by the item-code
                  timestamps = [x[1] for x in items]
                  items = [item_dict[x[0]] for x in items]
                  for i, t in zip(items, timestamps):
                      out_txt = [str(user_count), str(i)]
                      if add_time:
                          out_txt.append(str(t))
                      fw.write(sep.join(out_txt) + "\n")
                  user_count += 1
  
      print(f"Total {user_count-1} users, {count_del} removed")
      print(f"Processed model input data in {pname}")
      return user_dict, item_dict
  
file_path: recommenders/tests/unit/recommenders/models/test_sasrec_model.py
imports: import os
  import pytest
  from collections import defaultdict
label_desc: Use image node_id 2 for calling a global function with example usage: data_process_with_time(fname, pname, K, sep, item_set, add_time) and returns: user_dict,  item_dict